//============================================================================================
/**
 * @file	demo_dendou.c
 * @brief	ポケモン殿堂入りデモ
 * @author	taya		-> Hiroyuki Nakamura
 * @date	2006.04.26	-> 2009.03.26
 */
//============================================================================================
#include "common.h"

#include "gflib/touchpanel.h"
#include "system/wordset.h"
#include "system/snd_tool.h"
#include "system/snd_perap.h"
#include "system/wipe.h"
#include "system/gra_tool.h"
#include "system/fontproc.h"
#include "battle/graphic/batt_obj_gs_def.h"
#include "battle/trtype_def.h"
#include "field/pair_poke_info.h"
#include "field/onlyone_poke.h"
#include "msgdata/msg.naix"
#include "msgdata/msg_dendou_demo.h"

#include "../../application/pokethlon/pokethlon_poke.naix"
#include "../../data/mmodel/mmodel.naix"
#include "../../field/pair_poke_idx.h"
#include "../../field/field_trade.h"

#include "demo/demo_dendou.h"
#include "dendou_demo.naix"


//============================================================================================
//	定数定義
//============================================================================================

// メインシーケンス
enum {
	MAINSEQ_FADE_WAIT = 0,
	MAINSEQ_VFUNC,

	MAINSEQ_1ST_INIT,
	MAINSEQ_1ST_MAIN,
	MAINSEQ_1ST_END,

	MAINSEQ_2ND_INIT,
	MAINSEQ_2ND_MAIN,
	MAINSEQ_2ND_END,

	MAINSEQ_END
};

// シーン２の３Ｄ演出タスク定義
enum {
	S2_TASKPRI_CONFETTI_CTRL,

	S2_TASKPRI_LIGHT_CTRL,
	S2_TASKPRI_LIGHT,
	S2_TASKPRI_LIGHT_CTRL_TAIL,

	S2_TASKPRI_MAIN,
};

// OBJ ID
enum {
	// シーン１
	OBJID_1ST_POKE = 0,
	OBJID_1ST_POKE_S,
	OBJID_1ST_POKE_BACK,
	OBJID_1ST_POKE_BACK_S,
	OBJID_1ST_POKE_WALK,
	OBJID_1ST_POKE_WALK_S,
	OBJID_1ST_MAX,

	// シーン２
	OBJID_2ND_POKE1 = 0,
	OBJID_2ND_POKE2,
	OBJID_2ND_POKE3,
	OBJID_2ND_POKE4,
	OBJID_2ND_POKE5,
	OBJID_2ND_POKE6,
	OBJID_2ND_POKE_S1,
	OBJID_2ND_POKE_S2,
	OBJID_2ND_POKE_S3,
	OBJID_2ND_POKE_S4,
	OBJID_2ND_POKE_S5,
	OBJID_2ND_POKE_S6,
	OBJID_2ND_PLAYER,
	OBJID_2ND_PLAYER_S,
	OBJID_2ND_FLASH,
	OBJID_2ND_MAX,

	OBJID_MAX = OBJID_2ND_MAX
};

// BMPWIN ID
enum {
	S1_BMPWIN_TITLE = 0,	// タイトル
	S1_BMPWIN_NAME_L,		// ニックネーム（左開き）
	S1_BMPWIN_PARAM_L,		// パラメータ（左開き）
	S1_BMPWIN_MEMO_L,		// メモ（左開き）
	S1_BMPWIN_NAME_R,		// ニックネーム（右開き）
	S1_BMPWIN_PARAM_R,		// パラメータ（右開き）
	S1_BMPWIN_MEMO_R,		// メモ（右開き）
	S1_BMPWIN_MAX,

	S2_BMPWIN_MESSAGE = 0,	//「おめでとう」
	S2_BMPWIN_DATA,			// 時間など
	S2_BMPWIN_MAX,

	BMPWIN_MAX = S1_BMPWIN_MAX
};

#define	POKEGRA_TEX_SIZE	( 0x20 * 100 )	// ポケモン一枚絵データ：テクスチャサイズ
#define	POKEGRA_PAL_SIZE	( 0x20 )		// ポケモン一枚絵データ：パレットサイズ
#define	POKEWALK_PAL_SIZE	( 0x20 )		// 連れ歩きポケモンのパレットサイズ

// ポケモンデータ
typedef struct {
	POKEMON_PARAM * pp;
	PAIR_POKE_INFO	info;
	u32	rnd;
	u16	mons;
	u16	lv;
	u8	frm;
	u8	sex;
	u8	sex_put;
	u8	height;
	int	birth;
	u32	index;
	SOFT_SPRITE_ANIME	anim[2][SS_ANM_SEQ_MAX];
	u8	cgxBuf[2][POKEGRA_TEX_SIZE*2];
	u16	palBuf[16];
}POKE_DATA;

// 殿堂入り画面ワーク
typedef struct {
	DEMO_DENDOU_PARAM * prm;		// 外部設定データ

	// タスク関連
	TCB_PTR		vtask;
	void * vfunk;
	u16	vcnt;
	u16	vseq;

	GF_BGL_INI * bgl;	// BGL

	// BMPWIN
	GF_BGL_BMPWIN	win[BMPWIN_MAX];

	// メッセージ関連
	MSGDATA_MANAGER * mman;
	WORDSET * wset;
	STRBUF * tmpbuf1;
	STRBUF * tmpbuf2;

	// アーカイブ
	ARCHANDLE * ah;
	ARCHANDLE * pme_ah;

	// OBJ関連
	CATS_SYS_PTR	csp;
	CATS_RES_PTR	crp;
	CATS_ACT_PTR	cap[OBJID_MAX];

	// カメラ
	GF_CAMERA_PTR	camera;
	VecFx32			cameraTarget;
	CAMERA_ANGLE	cameraAngle;

	TCB_PTR			lightTask;		// ライトのタスク
	TCB_PTR			confettiTask;	// 紙吹雪のタスク

	// ポケモンデータ
	POKE_DATA	poke[TEMOTI_POKEMAX];
	int	pokeCount;

	int	main_seq;			// メインシーケンス
	int	next_seq;			// 次のシーケンス

	u16	sub_seq;			// サブシーケンス
	u16	mv_poke;			// 動作中ポケモン

	f32	sc_poke;			// ポケモンの拡縮率
	f32	sc_shadow;			// 影の拡縮率

	u32	f_anm_flg:1;		// 正面アニメ再生フラグ
	u32	b_anm_flg:1;		// 背面アニメ再生フラグ
	u32	eff_flg:1;			// ３Ｄエフェクト開始フラグ
	u32	fade_flg:1;			// フェード開始フラグ
	u32	fo_flg:1;			// フェードアウトフラグ
	u32	bg_scroll_flg:1;	// ＢＧスクロールフラグ
	u32	flash_flg:1;		// 光ＯＢＪ表示開始フラグ
	u32	dmy:25;

	int	s2_wf_div;			// シーン２のフェード分割数

	u16	s2_flash_wait;		// 光ＯＢＪ表示ウェイト
	u16	s2_flash_cnt;		// 光ＯＢＪ表示カウンタ

}DEMO_WORK;

typedef int (*pDendouDemoFunc)(DEMO_WORK*);


#define	CLA_H_NONE	( CLACT_U_HEADER_DATA_NONE )	// セルアクターヘッダーデータなし

#define	CLACT_ID_COMMON		( 55512 )	// この画面で使用するセルアクターのID

// キャラリソースID
enum {
	CHR_ID_POKEGRA1 = CLACT_ID_COMMON,
	CHR_ID_POKEGRA2,
	CHR_ID_POKEGRA3,
	CHR_ID_POKEGRA4,
	CHR_ID_POKEGRA5,
	CHR_ID_POKEGRA6,
	CHR_ID_POKEWALK1,
	CHR_ID_PLAYER,
	CHR_ID_FLASH,
	CHR_ID_MAX = CHR_ID_FLASH - CLACT_ID_COMMON + 1
};
// パレットリソースID
enum {
	PAL_ID_POKEGRA1 = CLACT_ID_COMMON,
	PAL_ID_POKEGRA2,
	PAL_ID_POKEGRA3,
	PAL_ID_POKEGRA4,
	PAL_ID_POKEGRA5,
	PAL_ID_POKEGRA6,
	PAL_ID_POKEWALK1,
	PAL_ID_POKEWALK2,
	PAL_ID_PLAYER,
	PAL_ID_SHADOW,
	PAL_ID_FLASH,
	PAL_ID_MAX = PAL_ID_FLASH - CLACT_ID_COMMON + 1
};
// セルリソースID
enum {
	CEL_ID_POKEGRA1 = CLACT_ID_COMMON,
	CEL_ID_POKEGRA2,
	CEL_ID_POKEWALK1,
	CEL_ID_FLASH,
	CEL_ID_MAX = CEL_ID_FLASH - CLACT_ID_COMMON + 1
};
// セルアニメリソースID
enum {
	ANM_ID_POKEGRA1 = CLACT_ID_COMMON,
	ANM_ID_POKEGRA2,
	ANM_ID_POKEWALK1,
	ANM_ID_FLASH,
	ANM_ID_MAX = ANM_ID_FLASH - CLACT_ID_COMMON + 1
};

// シーン１のＢＭＰ
// タイトル
#define	BMPWIN_TITLE_PX		( 0 )
#define	BMPWIN_TITLE_PY		( 0 )
#define	BMPWIN_TITLE_SX		( 32 )
#define	BMPWIN_TITLE_SY		( 2 )
#define	BMPWIN_TITLE_PAL	( 15 )
#define	BMPWIN_TITLE_CGX	( 1 )
// ニックネーム
#define	BMPWIN_NAME_LPX		( 18 )
#define	BMPWIN_NAME_RPX		( 0 )
#define	BMPWIN_NAME_PY		( 3 )
#define	BMPWIN_NAME_SX		( 14 )
#define	BMPWIN_NAME_SY		( 2 )
#define	BMPWIN_NAME_PAL		( 15 )
#define	BMPWIN_NAME_CGX		( BMPWIN_TITLE_CGX + BMPWIN_TITLE_SX * BMPWIN_TITLE_SY )
// パラメータ
#define	BMPWIN_PARAM_LPX	( 18 )
#define	BMPWIN_PARAM_RPX	( 0 )
#define	BMPWIN_PARAM_PY		( 6 )
#define	BMPWIN_PARAM_SX		( 14 )
#define	BMPWIN_PARAM_SY		( 4 )
#define	BMPWIN_PARAM_PAL	( 15 )
#define	BMPWIN_PARAM_CGX	( BMPWIN_NAME_CGX + BMPWIN_NAME_SX * BMPWIN_NAME_SY )
// メモ
#define	BMPWIN_MEMO_LPX		( 18 )
#define	BMPWIN_MEMO_RPX		( 0 )
#define	BMPWIN_MEMO_PY		( 12 )
#define	BMPWIN_MEMO_SX		( 14 )
#define	BMPWIN_MEMO_SY		( 9 )
#define	BMPWIN_MEMO_PAL		( 15 )
#define	BMPWIN_MEMO_CGX		( BMPWIN_PARAM_CGX + BMPWIN_PARAM_SX * BMPWIN_PARAM_SY )
// シーン２のＢＭＰ
//「おめでとう」
#define	BMPWIN_MESSAGE_PX	( 0 )
#define	BMPWIN_MESSAGE_PY	( 0 )
#define	BMPWIN_MESSAGE_SX	( 32 )
#define	BMPWIN_MESSAGE_SY	( 2 )
#define	BMPWIN_MESSAGE_PAL	( 15 )
#define	BMPWIN_MESSAGE_CGX	( 1 )
// 時間など
#define	BMPWIN_DATA_PX		( 0 )
#define	BMPWIN_DATA_PY		( 22 )
#define	BMPWIN_DATA_SX		( 32 )
#define	BMPWIN_DATA_SY		( 2 )
#define	BMPWIN_DATA_PAL		( 15 )
#define	BMPWIN_DATA_CGX		( BMPWIN_MESSAGE_CGX + BMPWIN_MESSAGE_SX * BMPWIN_MESSAGE_SY )

#define	FCOL_WN15			( GF_PRINTCOLOR_MAKE( 15, 2, 0 ) )		// フォントカラー

// 出会い方
typedef enum {
	POKE_MEET_CATCH,		///< ゲーム内で捕獲した
	POKE_MEET_BORN,			///< 自分でタマゴを孵した
	POKE_MEET_TRADE,		///< つうしん交換で
	POKE_MEET_KANTOU,		///< 赤緑から来た
	POKE_MEET_HOUEN,		///< ルビサファエメらから来た
	POKE_MEET_SHINOU,		///< D/P/PL
	POKE_MEET_SOMEWHERE,	///< どこかとおいばしょ（コロシアム専用）
	POKE_MEET_OTHER,		///< 後は全部うんめい的な出会い
	POKE_MEET_TSUBOTSUBO,	///< イベントポケモン：タンバのツボツボ
	POKE_MEET_HIKYAKU,		///< イベントポケモン：ひきゃく
}POKE_MEET_PATTERN;

// ＯＢＪ動作データ
typedef struct {
	s16	init_x;			// 初期Ｘ座標
	s16	init_y;			// 初期Ｙ座標
	s16	end_x;			// 終了Ｘ座標
	s16	end_y;			// 終了Ｙ座標
	f32	init_scale;		// 初期スケール値
	f32	end_scale;		// 終了スケール値
}S2_POKE_MOVE_DATA;

// OBJ移動計算 [ a 〜 b に c フレームで移動するときの、d フレーム目の座標 ]
#define	MV_CALC(a,b,c,d)	( ( ((abs(a-b)<<8) / c * d)>>8 ) )

//--------------------------------------------------------------------------------------------
// シーン１の各種データ定義
//--------------------------------------------------------------------------------------------
#define	S1_BG1_SCROLL_INIT_L	( 0 )		// ＢＧ１のスクロール初期座標（左開き）
#define	S1_BG2_SCROLL_INIT_L	( 0 )		// ＢＧ２のスクロール初期座標（左開き）
#define	S1_BG1_SCROLL_END_L		( -72 )		// ＢＧ１のスクロール終了座標（左開き）
#define	S1_BG2_SCROLL_END_L		( 72 )		// ＢＧ２のスクロール終了座標（左開き）

#define	S1_BG1_SCROLL_INIT_R	( 0 )		// ＢＧ１のスクロール初期座標（右開き）
#define	S1_BG2_SCROLL_INIT_R	( -184 )	// ＢＧ２のスクロール初期座標（右開き）
#define	S1_BG1_SCROLL_END_R		( 72 )		// ＢＧ１のスクロール終了座標（右開き）
#define	S1_BG2_SCROLL_END_R		( -256 )	// ＢＧ２のスクロール終了座標（右開き）

#define	S1_WIPE_BG_SCROLL_SPD	( 7 )		// ＢＧスクロール速度
#define	S1_CASE0_FRAME	( 10 )				// case 0: のフレーム数

#define	S1_B_POKE_Y		( 152 )				// 背面ポケモンのＹ座標

#define	S1_B_POKE_MV_SPD	( 24 )			// 背面ポケモンの移動速度
#define	S1_BS_POKE_MV_SPD	( 25 )			// 背面ポケモン（影）の移動速度

// 背面ポケモンと影の移動座標（左開き）
#define	S1_B_POKE_END_X_L	( 48 )
#define	S1_B_POKE_INIT_X_L	( S1_B_POKE_END_X_L + S1_B_POKE_MV_SPD * S1_CASE0_FRAME )
#define	S1_BS_POKE_END_X_L	( 46 )
#define	S1_BS_POKE_INIT_X_L	( S1_BS_POKE_END_X_L + S1_BS_POKE_MV_SPD * S1_CASE0_FRAME )

// 背面ポケモンと影の移動座標（右開き）
#define	S1_B_POKE_END_X_R	( 160 )
#define	S1_B_POKE_INIT_X_R	( S1_B_POKE_END_X_R - S1_B_POKE_MV_SPD * S1_CASE0_FRAME )
#define	S1_BS_POKE_END_X_R	( 158 )
#define	S1_BS_POKE_INIT_X_R	( S1_BS_POKE_END_X_R - S1_BS_POKE_MV_SPD * S1_CASE0_FRAME )

#define	S1_CASE3_FRAME		( 6 )			// case 3: のフレーム数

// 連れ歩きポケモンの移動データ
#define	S1_C3_W_POKE_SPD_X		( 19 )
#define	S1_C3_W_POKE_SPD_Y		( 7 )
#define	S1_C3_W_POKE_END_X_L	( 32 )
#define	S1_C3_W_POKE_END_Y_L	( 40 )
#define	S1_C3_W_POKE_INIT_X_L	( S1_C3_W_POKE_END_X_L - S1_C3_W_POKE_SPD_X * S1_CASE3_FRAME )
#define	S1_C3_W_POKE_INIT_Y_L	( S1_C3_W_POKE_END_Y_L - S1_C3_W_POKE_SPD_Y * S1_CASE3_FRAME )
#define	S1_C3_W_POKE_END_X_R	( 224 )
#define	S1_C3_W_POKE_END_Y_R	( 40 )
#define	S1_C3_W_POKE_INIT_X_R	( S1_C3_W_POKE_END_X_R + S1_C3_W_POKE_SPD_X * S1_CASE3_FRAME )
#define	S1_C3_W_POKE_INIT_Y_R	( S1_C3_W_POKE_END_Y_R - S1_C3_W_POKE_SPD_Y * S1_CASE3_FRAME )

// 連れ歩きポケモン（影）の移動データ
#define	S1_C3_WS_POKE_SPD_X		( 20 )
#define	S1_C3_WS_POKE_SPD_Y		( 7 )
#define	S1_C3_WS_POKE_END_X_L	( 31 )
#define	S1_C3_WS_POKE_END_Y_L	( 39 )
#define	S1_C3_WS_POKE_INIT_X_L	( S1_C3_WS_POKE_END_X_L - S1_C3_WS_POKE_SPD_X * S1_CASE3_FRAME )
#define	S1_C3_WS_POKE_INIT_Y_L	( S1_C3_WS_POKE_END_Y_L - S1_C3_WS_POKE_SPD_Y * S1_CASE3_FRAME )
#define	S1_C3_WS_POKE_END_X_R	( 225 )
#define	S1_C3_WS_POKE_END_Y_R	( 39 )
#define	S1_C3_WS_POKE_INIT_X_R	( S1_C3_WS_POKE_END_X_R + S1_C3_WS_POKE_SPD_X * S1_CASE3_FRAME )
#define	S1_C3_WS_POKE_INIT_Y_R	( S1_C3_WS_POKE_END_Y_R - S1_C3_WS_POKE_SPD_Y * S1_CASE3_FRAME )


#define	S1_CASE8_FRAME		( 8 )			// case 8: のフレーム数

// 正面ポケモンと影の移動データ
#define	S1_F_POKE_MV_X_SPD	( 21 )
#define	S1_F_POKE_MV_Y_SPD	( 16 )
#define	S1_FS_POKE_MV_X_SPD	( 24 )
#define	S1_FS_POKE_MV_Y_SPD	( 19 )

// 正面ポケモンと影の移動座標（左開き）
#define	S1_F_POKE_END_X_L	( 88 )
#define	S1_F_POKE_END_Y_L	( 88 )
#define	S1_F_POKE_INIT_X_L	( S1_F_POKE_END_X_L + S1_F_POKE_MV_X_SPD * S1_CASE8_FRAME )
#define	S1_F_POKE_INIT_Y_L	( S1_F_POKE_END_Y_L - S1_F_POKE_MV_Y_SPD * S1_CASE8_FRAME )
#define	S1_FS_POKE_END_X_L	( 104 )
#define	S1_FS_POKE_END_Y_L	( 72 )
#define	S1_FS_POKE_INIT_X_L	( S1_FS_POKE_END_X_L + S1_FS_POKE_MV_X_SPD * S1_CASE8_FRAME )
#define	S1_FS_POKE_INIT_Y_L	( S1_FS_POKE_END_Y_L - S1_FS_POKE_MV_Y_SPD * S1_CASE8_FRAME )

// 正面ポケモンと影の移動座標（右開き）
#define	S1_F_POKE_END_X_R	( 168 )
#define	S1_F_POKE_END_Y_R	( 88 )
#define	S1_F_POKE_INIT_X_R	( S1_F_POKE_END_X_R - S1_F_POKE_MV_X_SPD * S1_CASE8_FRAME )
#define	S1_F_POKE_INIT_Y_R	( S1_F_POKE_END_Y_R - S1_F_POKE_MV_Y_SPD * S1_CASE8_FRAME )
#define	S1_FS_POKE_END_X_R	( 152 )
#define	S1_FS_POKE_END_Y_R	( 72 )
#define	S1_FS_POKE_INIT_X_R	( S1_FS_POKE_END_X_R - S1_FS_POKE_MV_X_SPD * S1_CASE8_FRAME )
#define	S1_FS_POKE_INIT_Y_R	( S1_FS_POKE_END_Y_R - S1_FS_POKE_MV_Y_SPD * S1_CASE8_FRAME )

// case 8: のＢＧスクロールデータ
#define	S1_C8_BG2_SCROLL_MV_X		( 16 )
#define	S1_C8_BG2_SCROLL_MV_Y		( 8 )
#define	S1_C8_BG2_SCROLL_END_X_L	( 112 )
#define	S1_C8_BG2_SCROLL_END_Y_L	( 192 )
#define	S1_C8_BG2_SCROLL_INIT_X_L	( S1_C8_BG2_SCROLL_END_X_L - S1_C8_BG2_SCROLL_MV_X * S1_CASE8_FRAME )
#define	S1_C8_BG2_SCROLL_INIT_Y_L	( S1_C8_BG2_SCROLL_END_Y_L + S1_C8_BG2_SCROLL_MV_Y * S1_CASE8_FRAME )
#define	S1_C8_BG2_SCROLL_END_X_R	( 144 )
#define	S1_C8_BG2_SCROLL_END_Y_R	( 192 )
#define	S1_C8_BG2_SCROLL_INIT_X_R	( S1_C8_BG2_SCROLL_END_X_R + S1_C8_BG2_SCROLL_MV_X * S1_CASE8_FRAME )
#define	S1_C8_BG2_SCROLL_INIT_Y_R	( S1_C8_BG2_SCROLL_END_Y_R + S1_C8_BG2_SCROLL_MV_Y * S1_CASE8_FRAME )


#define	S1_CASE15_FRAME				( S1_CASE0_FRAME )		// case 15: のフレーム数

// case 15: のＢＧ０の移動データ
#define	S1_C15_BG0_SCROLL_MV_X		( 8 )
#define	S1_C15_BG0_SCROLL_MV_Y		( 20 )
#define	S1_C15_BG0_SCROLL_END_X_L	( -80 )
#define	S1_C15_BG0_SCROLL_END_Y_L	( -200 )
#define	S1_C15_BG0_SCROLL_END_X_R	( 80 )
#define	S1_C15_BG0_SCROLL_END_Y_R	( -200 )

// case 15: のＢＧ３の移動データ
#define	S1_C15_BG3_SCROLL_MV_X		( 6 )
#define	S1_C15_BG3_SCROLL_MV_Y		( 3 )
#define	S1_C15_BG3_SCROLL_END_X_L	( 60 )
#define	S1_C15_BG3_SCROLL_END_Y_L	( -30+256 )
#define	S1_C15_BG3_SCROLL_END_X_R	( -60+256 )
#define	S1_C15_BG3_SCROLL_END_Y_R	( -30+256 )

// case 15: の正面ポケモンの移動データ
#define	S1_C15_F_POKE_MV_SPD_X	( 4 )
#define	S1_C15_F_POKE_MV_SPD_Y	( 4 )
#define	S1_C15_F_POKE_END_X_L	( S1_F_POKE_END_X_L - S1_C15_F_POKE_MV_SPD_X * S1_CASE15_FRAME )
#define	S1_C15_F_POKE_END_Y_L	( S1_F_POKE_END_Y_L + S1_C15_F_POKE_MV_SPD_Y * S1_CASE15_FRAME )
#define	S1_C15_F_POKE_END_X_R	( S1_F_POKE_END_X_R + S1_C15_F_POKE_MV_SPD_X * S1_CASE15_FRAME )
#define	S1_C15_F_POKE_END_Y_R	( S1_F_POKE_END_Y_R + S1_C15_F_POKE_MV_SPD_Y * S1_CASE15_FRAME )
// case 15: の正面ポケモン（影）の移動データ
#define	S1_C15_FS_POKE_MV_SPD_X	( 4 )
#define	S1_C15_FS_POKE_MV_SPD_Y	( 4 )
#define	S1_C15_FS_POKE_END_X_L	( S1_FS_POKE_END_X_L - S1_C15_FS_POKE_MV_SPD_X * S1_CASE15_FRAME )
#define	S1_C15_FS_POKE_END_Y_L	( S1_FS_POKE_END_Y_L + S1_C15_FS_POKE_MV_SPD_Y * S1_CASE15_FRAME )
#define	S1_C15_FS_POKE_END_X_R	( S1_FS_POKE_END_X_R + S1_C15_FS_POKE_MV_SPD_X * S1_CASE15_FRAME )
#define	S1_C15_FS_POKE_END_Y_R	( S1_FS_POKE_END_Y_R + S1_C15_FS_POKE_MV_SPD_Y * S1_CASE15_FRAME )

// case 15: の背面ポケモンの移動データ
#define	S1_C15_B_POKE_MV_SPD_X	( 10 )
#define	S1_C15_B_POKE_MV_SPD_Y	( 10 )
#define	S1_C15_B_POKE_END_X_L	( S1_B_POKE_END_X_L + S1_C15_B_POKE_MV_SPD_X * S1_CASE15_FRAME )
#define	S1_C15_B_POKE_END_Y_L	( 152 + S1_C15_B_POKE_MV_SPD_X * S1_CASE15_FRAME )
#define	S1_C15_B_POKE_END_X_R	( S1_B_POKE_END_X_R + S1_C15_B_POKE_MV_SPD_X * S1_CASE15_FRAME )
#define	S1_C15_B_POKE_END_Y_R	( 152 + S1_C15_B_POKE_MV_SPD_X * S1_CASE15_FRAME )
// case 15: の背面ポケモン（影）の移動データ
#define	S1_C15_BS_POKE_MV_SPD_X	( 10 )
#define	S1_C15_BS_POKE_MV_SPD_Y	( 10 )
#define	S1_C15_BS_POKE_END_X_L	( S1_FS_POKE_END_X_L - S1_C15_FS_POKE_MV_SPD_X * S1_CASE15_FRAME )
#define	S1_C15_BS_POKE_END_Y_L	( 152 + S1_C15_FS_POKE_MV_SPD_X * S1_CASE15_FRAME )
#define	S1_C15_BS_POKE_END_X_R	( S1_FS_POKE_END_X_R + S1_C15_FS_POKE_MV_SPD_X * S1_CASE15_FRAME )
#define	S1_C15_BS_POKE_END_Y_R	( 152 + S1_C15_FS_POKE_MV_SPD_X * S1_CASE15_FRAME )

// case 15: の連れ歩きポケモンの移動データ
#define	S1_C15_W_POKE_MV_SPD_X	( 6 )
#define	S1_C15_W_POKE_MV_SPD_Y	( 7 )
#define	S1_C15_W_POKE_END_X_L	( S1_C3_W_POKE_END_X_L - S1_C15_W_POKE_MV_SPD_X * S1_CASE15_FRAME )
#define	S1_C15_W_POKE_END_Y_L	( S1_C3_W_POKE_END_Y_L - S1_C15_W_POKE_MV_SPD_Y * S1_CASE15_FRAME )
#define	S1_C15_W_POKE_END_X_R	( S1_C3_W_POKE_END_X_R - S1_C15_W_POKE_MV_SPD_X * S1_CASE15_FRAME )
#define	S1_C15_W_POKE_END_Y_R	( S1_C3_W_POKE_END_Y_R - S1_C15_W_POKE_MV_SPD_Y * S1_CASE15_FRAME )
// case 15: の連れ歩きポケモン（影）の移動データ
#define	S1_C15_WS_POKE_MV_SPD_X	( 6 )
#define	S1_C15_WS_POKE_MV_SPD_Y	( 7 )
#define	S1_C15_WS_POKE_END_X_L	( S1_C3_WS_POKE_END_X_L - S1_C15_WS_POKE_MV_SPD_X * S1_CASE15_FRAME )
#define	S1_C15_WS_POKE_END_Y_L	( S1_C3_WS_POKE_END_Y_L - S1_C15_WS_POKE_MV_SPD_Y * S1_CASE15_FRAME )
#define	S1_C15_WS_POKE_END_X_R	( S1_C3_WS_POKE_END_X_R - S1_C15_WS_POKE_MV_SPD_X * S1_CASE15_FRAME )
#define	S1_C15_WS_POKE_END_Y_R	( S1_C3_WS_POKE_END_Y_R - S1_C15_WS_POKE_MV_SPD_Y * S1_CASE15_FRAME )

//--------------------------------------------------------------------------------------------
// シーン２の各種データ定義
//--------------------------------------------------------------------------------------------
// シーン２のシーケンス
enum {
	S2_SUBSEQ_INIT_WAIT = 0,	// 初期ウェイト
	S2_SUBSEQ_POKE_IN,			// ポケモンイン
	S2_SUBSEQ_POKE_IN_WAIT,		// インした後のウェイト
	S2_SUBSEQ_EFF_START,		// ホワイトインセット＆文字面表示＆主人公表示＆３Ｄエフェクト開始
	S2_SUBSEQ_ST_SDW_MV,
	S2_SUBSEQ_MAIN,				// メイン
	S2_SUBSEQ_END_FADE_OUT,
	S2_SUBSEQ_END,				// 終了処理
};

#define	S2_INIT_WAIT	( 20 )		// 初期フレーム

#define	S2_POKEIN_FRM	( 6 )		// ポケモン移動フレーム数

#define	S2_POKEIN_WAIT	( 32 )		// ポケモン移動後のウェイト

#define	S2_EFF_START_WF_DIV		( 40 )							// 開始時のホワイトインの分割数
#define	S2_START_SHADOW_MV_FRM	( S2_EFF_START_WF_DIV * 2 )		// 開始時の影の移動フレーム数

#define	S2_BG2_SCROLL_SPD		( 2 )	// ＢＧ２のスクロール速度

// ポケモン初期座標
#define	S2_POKE01_INIT_X	( 168 )
#define	S2_POKE01_INIT_Y	( -40 )
#define	S2_POKE02_INIT_X	( -92 )
#define	S2_POKE02_INIT_Y	( 88 )
#define	S2_POKE03_INIT_X	( 348 )
#define	S2_POKE03_INIT_Y	( 88 )
#define	S2_POKE04_INIT_X	( 88 )
#define	S2_POKE04_INIT_Y	( -40 )
#define	S2_POKE05_INIT_X	( 336 )
#define	S2_POKE05_INIT_Y	( 0 )
#define	S2_POKE06_INIT_X	( -80 )
#define	S2_POKE06_INIT_Y	( 0 )

// ポケモン移動後の座標
#define	S2_POKE01_END_X		( 96 )
#define	S2_POKE01_END_Y		( 120 )
#define	S2_POKE02_END_X		( 160 )
#define	S2_POKE02_END_Y		( 120 )
#define	S2_POKE03_END_X		( 56 )
#define	S2_POKE03_END_Y		( 104 )
#define	S2_POKE04_END_X		( 200 )
#define	S2_POKE04_END_Y		( 104 )
#define	S2_POKE05_END_X		( 40 )
#define	S2_POKE05_END_Y		( 80 )
#define	S2_POKE06_END_X		( 216 )
#define	S2_POKE06_END_Y		( 80 )

// ポケモン（影）初期座標
#define	S2_POKE01_S_INIT_X	( S2_POKE01_END_X - 3 )
#define	S2_POKE01_S_INIT_Y	( 110 )
#define	S2_POKE02_S_INIT_X	( S2_POKE02_END_X - 3 )
#define	S2_POKE02_S_INIT_Y	( 110 )
#define	S2_POKE03_S_INIT_X	( S2_POKE03_END_X - 3 )
#define	S2_POKE03_S_INIT_Y	( 96 )
#define	S2_POKE04_S_INIT_X	( S2_POKE04_END_X - 3 )
#define	S2_POKE04_S_INIT_Y	( 96 )
#define	S2_POKE05_S_INIT_X	( S2_POKE05_END_X - 3 )
#define	S2_POKE05_S_INIT_Y	( 72 )
#define	S2_POKE06_S_INIT_X	( S2_POKE06_END_X - 3 )
#define	S2_POKE06_S_INIT_Y	( 72 )

// ポケモン（影）移動後の座標
#define	S2_POKE01_S_END_X	( S2_POKE01_S_INIT_X + 6 )
#define	S2_POKE01_S_END_Y	( 110 )
#define	S2_POKE02_S_END_X	( S2_POKE02_S_INIT_X + 6 )
#define	S2_POKE02_S_END_Y	( 110 )
#define	S2_POKE03_S_END_X	( S2_POKE03_S_INIT_X + 6 )
#define	S2_POKE03_S_END_Y	( 96 )
#define	S2_POKE04_S_END_X	( S2_POKE04_S_INIT_X + 6 )
#define	S2_POKE04_S_END_Y	( 96 )
#define	S2_POKE05_S_END_X	( S2_POKE05_S_INIT_X + 6 )
#define	S2_POKE05_S_END_Y	( 72 )
#define	S2_POKE06_S_END_X	( S2_POKE06_S_INIT_X + 6 )
#define	S2_POKE06_S_END_Y	( 72 )

// プレイヤー初期座標
#define	S2_PLAYER_INIT_X	( 128 )
#define	S2_PLAYER_INIT_Y	( 128 )

// プレイヤー（影）初期座標
#define	S2_PLAYER_S_INIT_X	( S2_PLAYER_INIT_X - 3 )
#define	S2_PLAYER_S_INIT_Y	( 120 )
// プレイヤー（影）移動後の座標
#define	S2_PLAYER_S_END_X	( S2_PLAYER_S_INIT_X + 6 )
#define	S2_PLAYER_S_END_Y	( 120 )

// 終了演出時のポケモン初期座標
#define	S2_POKE01_E_INIT_X	( S2_POKE01_END_X )
#define	S2_POKE01_E_INIT_Y	( S2_POKE01_END_Y )
#define	S2_POKE02_E_INIT_X	( S2_POKE02_END_X )
#define	S2_POKE02_E_INIT_Y	( S2_POKE02_END_Y )
#define	S2_POKE03_E_INIT_X	( S2_POKE03_END_X )
#define	S2_POKE03_E_INIT_Y	( S2_POKE03_END_Y )
#define	S2_POKE04_E_INIT_X	( S2_POKE04_END_X )
#define	S2_POKE04_E_INIT_Y	( S2_POKE04_END_Y )
#define	S2_POKE05_E_INIT_X	( S2_POKE05_END_X )
#define	S2_POKE05_E_INIT_Y	( S2_POKE05_END_Y )
#define	S2_POKE06_E_INIT_X	( S2_POKE06_END_X )
#define	S2_POKE06_E_INIT_Y	( S2_POKE06_END_Y )

// 終了演出時のポケモン移動後の座標
#define	S2_POKE01_E_END_X	( 108 )
#define	S2_POKE01_E_END_Y	( 100 )
#define	S2_POKE02_E_END_X	( 148 )
#define	S2_POKE02_E_END_Y	( 100 )
#define	S2_POKE03_E_END_X	( 84 )
#define	S2_POKE03_E_END_Y	( 90 )
#define	S2_POKE04_E_END_X	( 170 )
#define	S2_POKE04_E_END_Y	( 90 )
#define	S2_POKE05_E_END_X	( 64 )
#define	S2_POKE05_E_END_Y	( 75 )
#define	S2_POKE06_E_END_X	( 190 )
#define	S2_POKE06_E_END_Y	( 75 )

// 終了演出時のプレイヤー初期座標
#define	S2_PLAYER_E_INIT_X	( S2_PLAYER_INIT_X )
#define	S2_PLAYER_E_INIT_Y	( S2_PLAYER_INIT_Y )
// 終了演出時のプレイヤー移動後の座標
#define	S2_PLAYER_E_END_X	( 128 )
#define	S2_PLAYER_E_END_Y	( 120 )

// 終了演出時のポケモン（影）初期座標
#define	S2_POKE01_ES_INIT_X	( S2_POKE01_END_X )
#define	S2_POKE01_ES_INIT_Y	( 90 )
#define	S2_POKE02_ES_INIT_X	( S2_POKE02_END_X )
#define	S2_POKE02_ES_INIT_Y	( 90 )
#define	S2_POKE03_ES_INIT_X	( S2_POKE03_END_X )
#define	S2_POKE03_ES_INIT_Y	( 80 )
#define	S2_POKE04_ES_INIT_X	( S2_POKE04_END_X )
#define	S2_POKE04_ES_INIT_Y	( 80 )
#define	S2_POKE05_ES_INIT_X	( S2_POKE05_END_X )
#define	S2_POKE05_ES_INIT_Y	( 60 )
#define	S2_POKE06_ES_INIT_X	( S2_POKE06_END_X )
#define	S2_POKE06_ES_INIT_Y	( 60 )

// 終了演出時のポケモン（影）移動後の座標
#define	S2_POKE01_ES_END_X	( 108 )
#define	S2_POKE01_ES_END_Y	( 100 )
#define	S2_POKE02_ES_END_X	( 148 )
#define	S2_POKE02_ES_END_Y	( 100 )
#define	S2_POKE03_ES_END_X	( 84 )
#define	S2_POKE03_ES_END_Y	( 90 )
#define	S2_POKE04_ES_END_X	( 170 )
#define	S2_POKE04_ES_END_Y	( 90 )
#define	S2_POKE05_ES_END_X	( 64 )
#define	S2_POKE05_ES_END_Y	( 75 )
#define	S2_POKE06_ES_END_X	( 190 )
#define	S2_POKE06_ES_END_Y	( 75 )

// 終了演出時のプレイヤー（影）初期座標
#define	S2_PLAYER_ES_INIT_X	( S2_PLAYER_INIT_X )
#define	S2_PLAYER_ES_INIT_Y	( 100 )
// 終了演出時のプレイヤー（影）移動後の座標
#define	S2_PLAYER_ES_END_X	( 128 )
#define	S2_PLAYER_ES_END_Y	( 120 )

#define	S2_END_BO_DIV			( 15 )						// 終了演出開始時のフェード分割数
#define	S2_END_FADE_FRM			( S2_END_BO_DIV * 4 )		// フェードフレーム数
#define	S2_END_FADE_FRM_HALF	( S2_END_FADE_FRM / 2 )		// フェードフレーム数の半分

#define	S2_FLASH_ANM_FRM	( 12 )							// 光アニメのフレーム数
#define	S2_FLASH_WAIT_MIN	( S2_FLASH_ANM_FRM + 16 )		// 光表示ウェイトの最小値
#define	S2_FLASH_WAIT_MAX	( 0xff )						// 光表示ウェイトの最大値
#define	S2_FLASH_X_MIN		( 16 )							// 光表示Ｘ座標最小値
#define	S2_FLASH_X_MAX		( 240 )							// 光表示Ｘ座標最大値
#define	S2_FLASH_Y_MIN		( 16 )							// 光表示Ｙ座標最小値
#define	S2_FLASH_Y_MAX		( 80 )							// 光表示Ｙ座標最大値
#define	S2_FLASH_X_SIZ		( S2_FLASH_X_MAX - S2_FLASH_X_MIN )		// 光表示Ｘ座標エリアサイズ
#define	S2_FLASH_Y_SIZ		( S2_FLASH_Y_MAX - S2_FLASH_Y_MIN )		// 光表示Ｙ座標エリアサイズ

// 影・シルエットカラー定義
enum {
	SHADOW_COL_BLACK = 0,	// 黒
	SHADOW_COL_WHITE,		// 白
	SHADOW_COL_RED,			// 赤
};

// 各シーケンスのフレーム数
#define	S1_CASE2_FRAME	( 50 )
#define	S1_CASE5_FRAME	( 20 )
#define	S1_CASE7_FRAME	( 60 )
#define	S1_CASE10_FRAME	( 40 )
#define	S1_CASE12_FRAME	( 20 )
#define	S1_CASE14_FRAME	( 240 )
#define	S1_CASE16_FRAME	( 60 )


//============================================================================================
//	プロトタイプ宣言
//============================================================================================
static void VramInit(void);
static void VBlankFunc( TCB_PTR tcb, void * work );
static void BgInit( DEMO_WORK * wk );
static void BgExit( DEMO_WORK * wk );
static void ObjInit( DEMO_WORK * wk );
static void ObjExit( DEMO_WORK * wk );
static void ObjAnmMain( DEMO_WORK * wk );

static int MainSeq_FadeWait( DEMO_WORK * wk );
static int MainSeq_VFunc( DEMO_WORK * wk );

static int MainSeq_1stInit( DEMO_WORK * wk );
static int MainSeq_1stMain( DEMO_WORK * wk );
static int MainSeq_1stEnd( DEMO_WORK * wk );
static int MainSeq_2ndInit( DEMO_WORK * wk );
static int MainSeq_2ndMain( DEMO_WORK * wk );
static int MainSeq_2ndEnd( DEMO_WORK * wk );

static void PokeDataMake( DEMO_WORK * wk );

static void PokePaletteGet( DEMO_WORK * wk, u32 pokeID, u32 objID );
static void PokePaletteSet( DEMO_WORK * wk, u32 pokeID, u32 objID );

static int GetMonsArcIdx( const int inMonsNo, const u16 inFormNo, const int inSex );
static void PokeAnimTaskSet( DEMO_WORK * wk, int pokeID, int objID, BOOL voice, int dir );

static void Scene01BgInit( DEMO_WORK * wk );
static void Scene01BgExit( DEMO_WORK * wk );
static void Scene01BgGraphicLoad( DEMO_WORK * wk );
static void Scene01BmpInit( DEMO_WORK * wk );
static void Scene01BmpExit( DEMO_WORK * wk );
static void ObjInit1st( DEMO_WORK * wk, u32 num );
static void ObjExit1st( DEMO_WORK * wk );
static int VFunc1stSceneLeft( DEMO_WORK * wk );
static int VFunc1stSceneRight( DEMO_WORK * wk );
static void Scene01_MoveInit( DEMO_WORK * wk );
static POKE_MEET_PATTERN GetPokeMeetPattern( DEMO_WORK* wk, POKEMON_PARAM* pp, const MYSTATUS* player );

static int VFunc2ndSceneMain( DEMO_WORK * wk );

static void Scene02VBlankFunc( TCB_PTR tcb, void * work );
static void Scene02BgInit( DEMO_WORK * wk );
static void Scene02BgExit( DEMO_WORK * wk );
static void Scene02BgGraphicLoad( DEMO_WORK * wk );
static void Scene02BmpInit( DEMO_WORK * wk );
static void Scene02BmpExit( DEMO_WORK * wk );
static void Scene02ObjInit( DEMO_WORK * wk );
static void Scene02ObjExit( DEMO_WORK * wk );
static void Scene02Init3D( DEMO_WORK * wk );
static void Scene02InitCamera( DEMO_WORK* wk );
static void Scene02Exit3D( DEMO_WORK * wk );
static void Scene02Main3D( DEMO_WORK * wk );
static void Scene02FadeSet( DEMO_WORK * wk );
static void Scene02FadeOutSet( DEMO_WORK * wk );

static TCB_PTR CreateLightCtrlTask( DEMO_WORK * wk );
static void AddLightTask( TCB_PTR ctrlTask, fx16 px, fx32 angle );
static void DrawLight( TCB_PTR tcb );
static void DeleteLightCtrlTask( TCB_PTR tcb );
static BOOL WaitLightTaskDelete(void);
static TCB_PTR CreateConfettiTask( DEMO_WORK* wk );
static void DrawConfetti( TCB_PTR tcb );
static void StartConfettiDraw( TCB_PTR tcb );
static void DeleteConfettiTask( TCB_PTR tcb );

static void PokeObjAdd( DEMO_WORK * wk, u32 num );


//============================================================================================
//	グローバル変数
//============================================================================================

// VRAM割り振り
static const GF_BGL_DISPVRAM VramTbl = {
	GX_VRAM_BG_128_B,				// メイン2DエンジンのBG
	GX_VRAM_BGEXTPLTT_NONE,			// メイン2DエンジンのBG拡張パレット

	GX_VRAM_SUB_BG_128_C,			// サブ2DエンジンのBG
	GX_VRAM_SUB_BGEXTPLTT_NONE,		// サブ2DエンジンのBG拡張パレット

	GX_VRAM_OBJ_64_E,				// メイン2DエンジンのOBJ
	GX_VRAM_OBJEXTPLTT_NONE,		// メイン2DエンジンのOBJ拡張パレット

	GX_VRAM_SUB_OBJ_16_I,			// サブ2DエンジンのOBJ
	GX_VRAM_SUB_OBJEXTPLTT_NONE,	// サブ2DエンジンのOBJ拡張パレット

	GX_VRAM_TEX_0_A,				// テクスチャイメージスロット
	GX_VRAM_TEXPLTT_01_FG			// テクスチャパレットスロット
};

// メインシーケンス
static const pDendouDemoFunc MainSeqFunc[] = {
	MainSeq_FadeWait,
	MainSeq_VFunc,

	MainSeq_1stInit,
	MainSeq_1stMain,
	MainSeq_1stEnd,

	MainSeq_2ndInit,
	MainSeq_2ndMain,
	MainSeq_2ndEnd,
};

// シーン１のＢＭＰデータ
static const BMPWIN_DAT Scene01BmpWinData[] =
{
	{	// タイトル
		GF_BGL_FRAME0_M, BMPWIN_TITLE_PX, BMPWIN_TITLE_PY,
		BMPWIN_TITLE_SX, BMPWIN_TITLE_SY, BMPWIN_TITLE_PAL, BMPWIN_TITLE_CGX
	},
	{	// ニックネーム（左開き）
		GF_BGL_FRAME0_M, BMPWIN_NAME_LPX, BMPWIN_NAME_PY,
		BMPWIN_NAME_SX, BMPWIN_NAME_SY, BMPWIN_NAME_PAL, BMPWIN_NAME_CGX
	},
	{	// パラメータ（左開き）
		GF_BGL_FRAME0_M, BMPWIN_PARAM_LPX, BMPWIN_PARAM_PY,
		BMPWIN_PARAM_SX, BMPWIN_PARAM_SY, BMPWIN_PARAM_PAL, BMPWIN_PARAM_CGX
	},
	{	// メモ（左開き）
		GF_BGL_FRAME0_M, BMPWIN_MEMO_LPX, BMPWIN_MEMO_PY,
		BMPWIN_MEMO_SX, BMPWIN_MEMO_SY, BMPWIN_MEMO_PAL, BMPWIN_MEMO_CGX
	},
	{	// ニックネーム（右開き）
		GF_BGL_FRAME0_M, BMPWIN_NAME_RPX, BMPWIN_NAME_PY,
		BMPWIN_NAME_SX, BMPWIN_NAME_SY, BMPWIN_NAME_PAL, BMPWIN_NAME_CGX
	},
	{	// パラメータ（右開き）
		GF_BGL_FRAME0_M, BMPWIN_PARAM_RPX, BMPWIN_PARAM_PY,
		BMPWIN_PARAM_SX, BMPWIN_PARAM_SY, BMPWIN_PARAM_PAL, BMPWIN_PARAM_CGX
	},
	{	// メモ（右開き）
		GF_BGL_FRAME0_M, BMPWIN_MEMO_RPX, BMPWIN_MEMO_PY,
		BMPWIN_MEMO_SX, BMPWIN_MEMO_SY, BMPWIN_MEMO_PAL, BMPWIN_MEMO_CGX
	},
};

// シーン１のＯＢＪデータ
static const TCATS_OBJECT_ADD_PARAM_S Cla1stScenePrm[] =
{
	{	// 正面
		512, 480, 0,
		0, 0, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
		{ CHR_ID_POKEGRA1, PAL_ID_POKEGRA1, CEL_ID_POKEGRA1, ANM_ID_POKEGRA1, CLA_H_NONE, CLA_H_NONE },
		2, 0
	},
	{	// 正面影
		512, 480, 0,
		0, 1, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
		{ CHR_ID_POKEGRA1, PAL_ID_POKEGRA2, CEL_ID_POKEGRA1, ANM_ID_POKEGRA1, CLA_H_NONE, CLA_H_NONE },
		2, 0
	},
	{	// 背面
		512, 480, 0,
		0, 2, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
		{ CHR_ID_POKEGRA2, PAL_ID_POKEGRA3, CEL_ID_POKEGRA2, ANM_ID_POKEGRA2, CLA_H_NONE, CLA_H_NONE },
		3, 0
	},
	{	// 背面影
		512, 480, 0,
		0, 3, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
		{ CHR_ID_POKEGRA2, PAL_ID_POKEGRA4, CEL_ID_POKEGRA2, ANM_ID_POKEGRA2, CLA_H_NONE, CLA_H_NONE },
		3, 0
	},
	{	// 連れ歩き
		512, 480, 0,
		0, 4, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
		{ CHR_ID_POKEWALK1, PAL_ID_POKEWALK1, CEL_ID_POKEWALK1, ANM_ID_POKEWALK1, CLA_H_NONE, CLA_H_NONE },
		2, 0
	},
	{	// 連れ歩き影
		512, 480, 0,
		0, 5, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
		{ CHR_ID_POKEWALK1, PAL_ID_POKEWALK2, CEL_ID_POKEWALK1, ANM_ID_POKEWALK1, CLA_H_NONE, CLA_H_NONE },
		2, 0
	},
};

// シーン２のＢＭＰデータ
static const BMPWIN_DAT Scene02BmpWinData[] =
{
	{	//「おめでとう」
		GF_BGL_FRAME1_M, BMPWIN_MESSAGE_PX, BMPWIN_MESSAGE_PY,
		BMPWIN_MESSAGE_SX, BMPWIN_MESSAGE_SY, BMPWIN_MESSAGE_PAL, BMPWIN_MESSAGE_CGX
	},
	{	// 時間など
		GF_BGL_FRAME1_M, BMPWIN_DATA_PX, BMPWIN_DATA_PY,
		BMPWIN_DATA_SX, BMPWIN_DATA_SY, BMPWIN_DATA_PAL, BMPWIN_DATA_CGX
	},
};

// シーン２のＯＢＪデータ
static const TCATS_OBJECT_ADD_PARAM_S Cla2ndScenePrm[] =
{
	{	// 正面
		S2_POKE01_INIT_X, S2_POKE01_INIT_Y, 0,
		0, 20, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
		{ CHR_ID_POKEGRA1, PAL_ID_POKEGRA1, CEL_ID_POKEGRA1, ANM_ID_POKEGRA1, CLA_H_NONE, CLA_H_NONE },
		2, 0
	},
	{	// 正面
		S2_POKE02_INIT_X, S2_POKE02_INIT_Y, 0,
		0, 21, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
		{ CHR_ID_POKEGRA2, PAL_ID_POKEGRA2, CEL_ID_POKEGRA1, ANM_ID_POKEGRA1, CLA_H_NONE, CLA_H_NONE },
		2, 0
	},
	{	// 正面
		S2_POKE03_INIT_X, S2_POKE03_INIT_Y, 0,
		0, 22, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
		{ CHR_ID_POKEGRA3, PAL_ID_POKEGRA3, CEL_ID_POKEGRA1, ANM_ID_POKEGRA1, CLA_H_NONE, CLA_H_NONE },
		2, 0
	},
	{	// 正面
		S2_POKE04_INIT_X, S2_POKE04_INIT_Y, 0,
		0, 23, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
		{ CHR_ID_POKEGRA4, PAL_ID_POKEGRA4, CEL_ID_POKEGRA1, ANM_ID_POKEGRA1, CLA_H_NONE, CLA_H_NONE },
		2, 0
	},
	{	// 正面
		S2_POKE05_INIT_X, S2_POKE05_INIT_Y, 0,
		0, 24, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
		{ CHR_ID_POKEGRA5, PAL_ID_POKEGRA5, CEL_ID_POKEGRA1, ANM_ID_POKEGRA1, CLA_H_NONE, CLA_H_NONE },
		2, 0
	},
	{	// 正面
		S2_POKE06_INIT_X, S2_POKE06_INIT_Y, 0,
		0, 25, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
		{ CHR_ID_POKEGRA6, PAL_ID_POKEGRA6, CEL_ID_POKEGRA1, ANM_ID_POKEGRA1, CLA_H_NONE, CLA_H_NONE },
		2, 0
	},
	{	// 影
		S2_POKE01_S_INIT_X, S2_POKE01_S_INIT_Y, 0,
		0, 40, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
		{ CHR_ID_POKEGRA1, PAL_ID_SHADOW, CEL_ID_POKEGRA1, ANM_ID_POKEGRA1, CLA_H_NONE, CLA_H_NONE },
		3, 0
	},
	{	// 影
		S2_POKE02_S_INIT_X, S2_POKE02_S_INIT_Y, 0,
		0, 40, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
		{ CHR_ID_POKEGRA2, PAL_ID_SHADOW, CEL_ID_POKEGRA1, ANM_ID_POKEGRA1, CLA_H_NONE, CLA_H_NONE },
		3, 0
	},
	{	// 影
		S2_POKE03_S_INIT_X, S2_POKE03_S_INIT_Y, 0,
		0, 40, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
		{ CHR_ID_POKEGRA3, PAL_ID_SHADOW, CEL_ID_POKEGRA1, ANM_ID_POKEGRA1, CLA_H_NONE, CLA_H_NONE },
		3, 0
	},
	{	// 影
		S2_POKE04_S_INIT_X, S2_POKE04_S_INIT_Y, 0,
		0, 40, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
		{ CHR_ID_POKEGRA4, PAL_ID_SHADOW, CEL_ID_POKEGRA1, ANM_ID_POKEGRA1, CLA_H_NONE, CLA_H_NONE },
		3, 0
	},
	{	// 影
		S2_POKE05_S_INIT_X, S2_POKE05_S_INIT_Y, 0,
		0, 40, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
		{ CHR_ID_POKEGRA5, PAL_ID_SHADOW, CEL_ID_POKEGRA1, ANM_ID_POKEGRA1, CLA_H_NONE, CLA_H_NONE },
		3, 0
	},
	{	// 影
		S2_POKE06_S_INIT_X, S2_POKE06_S_INIT_Y, 0,
		0, 40, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
		{ CHR_ID_POKEGRA6, PAL_ID_SHADOW, CEL_ID_POKEGRA1, ANM_ID_POKEGRA1, CLA_H_NONE, CLA_H_NONE },
		3, 0
	},
	{	// プレイヤー
		S2_PLAYER_INIT_X, S2_PLAYER_INIT_Y, 0,
		0, 10, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
		{ CHR_ID_PLAYER, PAL_ID_PLAYER, CEL_ID_POKEGRA1, ANM_ID_POKEGRA1, CLA_H_NONE, CLA_H_NONE },
		2, 0
	},
	{	// プレイヤー・影
		S2_PLAYER_S_INIT_X, S2_PLAYER_S_INIT_Y, 0,
		0, 40, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
		{ CHR_ID_PLAYER, PAL_ID_SHADOW, CEL_ID_POKEGRA1, ANM_ID_POKEGRA1, CLA_H_NONE, CLA_H_NONE },
		3, 0
	},
	{	// プレイヤー・影
		0, 0, 0,
		0, 0, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
		{ CHR_ID_FLASH, PAL_ID_FLASH, CEL_ID_FLASH, ANM_ID_FLASH, CLA_H_NONE, CLA_H_NONE },
		2, 0
	},
};

// シーン２の最初のポケモン集合動作
static const S2_POKE_MOVE_DATA Scene02PokeMoveData[] =
{
	{ S2_POKE01_INIT_X, S2_POKE01_INIT_Y, S2_POKE01_END_X, S2_POKE01_END_Y, 1.0, 1.0 },
	{ S2_POKE02_INIT_X, S2_POKE02_INIT_Y, S2_POKE02_END_X, S2_POKE02_END_Y, 1.0, 1.0 },
	{ S2_POKE03_INIT_X, S2_POKE03_INIT_Y, S2_POKE03_END_X, S2_POKE03_END_Y, 1.0, 1.0 },
	{ S2_POKE04_INIT_X, S2_POKE04_INIT_Y, S2_POKE04_END_X, S2_POKE04_END_Y, 1.0, 1.0 },
	{ S2_POKE05_INIT_X, S2_POKE05_INIT_Y, S2_POKE05_END_X, S2_POKE05_END_Y, 1.0, 1.0 },
	{ S2_POKE06_INIT_X, S2_POKE06_INIT_Y, S2_POKE06_END_X, S2_POKE06_END_Y, 1.0, 1.0 },
/*	セルの継ぎ目が目立つので縮小をやめます
	{ S2_POKE01_INIT_X, S2_POKE01_INIT_Y, S2_POKE01_END_X, S2_POKE01_END_Y, 1.0, 1.0 },
	{ S2_POKE02_INIT_X, S2_POKE02_INIT_Y, S2_POKE02_END_X, S2_POKE02_END_Y, 1.0, 1.0 },
	{ S2_POKE03_INIT_X, S2_POKE03_INIT_Y, S2_POKE03_END_X, S2_POKE03_END_Y, 1.0, 0.8 },
	{ S2_POKE04_INIT_X, S2_POKE04_INIT_Y, S2_POKE04_END_X, S2_POKE04_END_Y, 1.0, 0.8 },
	{ S2_POKE05_INIT_X, S2_POKE05_INIT_Y, S2_POKE05_END_X, S2_POKE05_END_Y, 1.0, 0.6 },
	{ S2_POKE06_INIT_X, S2_POKE06_INIT_Y, S2_POKE06_END_X, S2_POKE06_END_Y, 1.0, 0.6 },
*/
};

// シーン２の最初の影動作
static const S2_POKE_MOVE_DATA Scene02ShadowMove[] =
{
	{ S2_POKE01_S_INIT_X, S2_POKE01_S_INIT_Y, S2_POKE01_S_END_X, S2_POKE01_S_END_Y, 1.0, 1.0 },
	{ S2_POKE02_S_INIT_X, S2_POKE02_S_INIT_Y, S2_POKE02_S_END_X, S2_POKE02_S_END_Y, 1.0, 1.0 },
	{ S2_POKE03_S_INIT_X, S2_POKE03_S_INIT_Y, S2_POKE03_S_END_X, S2_POKE03_S_END_Y, 1.0, 1.0 },
	{ S2_POKE04_S_INIT_X, S2_POKE04_S_INIT_Y, S2_POKE04_S_END_X, S2_POKE04_S_END_Y, 1.0, 1.0 },
	{ S2_POKE05_S_INIT_X, S2_POKE05_S_INIT_Y, S2_POKE05_S_END_X, S2_POKE05_S_END_Y, 1.0, 1.0 },
	{ S2_POKE06_S_INIT_X, S2_POKE06_S_INIT_Y, S2_POKE06_S_END_X, S2_POKE06_S_END_Y, 1.0, 1.0 },

	{ S2_PLAYER_S_INIT_X, S2_PLAYER_S_INIT_Y, S2_PLAYER_S_END_X, S2_PLAYER_S_END_Y, 1.0, 1.0 },
};

// シーン２の最後のポケモンと主人公の動作
static const S2_POKE_MOVE_DATA Scene02EndObjMove[] =
{
	{ S2_POKE01_E_INIT_X, S2_POKE01_E_INIT_Y, S2_POKE01_E_END_X, S2_POKE01_E_END_Y, 1.0, 0.8 },
	{ S2_POKE02_E_INIT_X, S2_POKE02_E_INIT_Y, S2_POKE02_E_END_X, S2_POKE02_E_END_Y, 1.0, 0.8 },
	{ S2_POKE03_E_INIT_X, S2_POKE03_E_INIT_Y, S2_POKE03_E_END_X, S2_POKE03_E_END_Y, 1.0, 0.75 },
	{ S2_POKE04_E_INIT_X, S2_POKE04_E_INIT_Y, S2_POKE04_E_END_X, S2_POKE04_E_END_Y, 1.0, 0.75 },
	{ S2_POKE05_E_INIT_X, S2_POKE05_E_INIT_Y, S2_POKE05_E_END_X, S2_POKE05_E_END_Y, 1.0, 0.7 },
	{ S2_POKE06_E_INIT_X, S2_POKE06_E_INIT_Y, S2_POKE06_E_END_X, S2_POKE06_E_END_Y, 1.0, 0.7 },

	{ S2_PLAYER_E_INIT_X, S2_PLAYER_E_INIT_Y, S2_PLAYER_E_END_X, S2_PLAYER_E_END_Y, 1.0, 0.7 },
};
// シーン２の最後のポケモンと主人公の影の動作
static const S2_POKE_MOVE_DATA Scene02EndObjSMove[] =
{
	{ S2_POKE01_ES_INIT_X, S2_POKE01_ES_INIT_Y, S2_POKE01_ES_END_X, S2_POKE01_ES_END_Y, 1.0, 0.9 },
	{ S2_POKE02_ES_INIT_X, S2_POKE02_ES_INIT_Y, S2_POKE02_ES_END_X, S2_POKE02_ES_END_Y, 1.0, 0.9 },
	{ S2_POKE03_ES_INIT_X, S2_POKE03_ES_INIT_Y, S2_POKE03_ES_END_X, S2_POKE03_ES_END_Y, 1.0, 0.8 },
	{ S2_POKE04_ES_INIT_X, S2_POKE04_ES_INIT_Y, S2_POKE04_ES_END_X, S2_POKE04_ES_END_Y, 1.0, 0.8 },
	{ S2_POKE05_ES_INIT_X, S2_POKE05_ES_INIT_Y, S2_POKE05_ES_END_X, S2_POKE05_ES_END_Y, 1.0, 0.75 },
	{ S2_POKE06_ES_INIT_X, S2_POKE06_ES_INIT_Y, S2_POKE06_ES_END_X, S2_POKE06_ES_END_Y, 1.0, 0.75 },

	{ S2_PLAYER_ES_INIT_X, S2_PLAYER_ES_INIT_Y, S2_PLAYER_ES_END_X, S2_PLAYER_ES_END_Y, 1.0, 0.8 },
};

// 影・シルエット用：黒パレット
static const u16 ShadowBlack[] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
// 影・シルエット用：白パレット
static const u16 ShadowWhite[] = {
	0x7fff,0x7fff,0x7fff,0x7fff,0x7fff,0x7fff,0x7fff,0x7fff,
	0x7fff,0x7fff,0x7fff,0x7fff,0x7fff,0x7fff,0x7fff,0x7fff,
};
// 影・シルエット用：赤パレット
static const u16 ShadowRed[] = {
	0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,
};



//--------------------------------------------------------------------------------------------
/**
 * プロセス初期化
 *
 * @param	proc
 * @param	seq
 *
 * @return	PROC_RES_FINISH
 */
//--------------------------------------------------------------------------------------------
PROC_RESULT  DemoDendouPROC_Init( PROC* proc, int* seq )
{
	DEMO_WORK * wk;
	int	i;

	// 割り込み停止
	sys_VBlankFuncChange( NULL, NULL );
	sys_HBlankIntrStop();
	// 表示初期化
	GF_Disp_GX_VisibleControlDirect( 0 );
	GF_Disp_GXS_VisibleControlDirect( 0 );
	// ブレンド初期化
	G2_BlendNone();
	G2S_BlendNone();
	// メイン画面をメインに
	GX_SetDispSelect( GX_DISP_SELECT_MAIN_SUB );

	sys_CreateHeap( HEAPID_BASE_APP, HEAPID_DENDOU_DEMO, 0x50000 );

	wk = PROC_AllocWork( proc, sizeof(DEMO_WORK), HEAPID_DENDOU_DEMO );
	MI_CpuClear8( wk, sizeof(DEMO_WORK) );

	wk->prm = PROC_GetParentWork( proc );

	wk->mman = MSGMAN_Create( MSGMAN_TYPE_NORMAL, ARC_MSG, NARC_msg_dendou_demo_dat, HEAPID_DENDOU_DEMO );
	wk->wset = WORDSET_Create( HEAPID_DENDOU_DEMO );
	wk->tmpbuf1 = STRBUF_Create( 500, HEAPID_DENDOU_DEMO );
	wk->tmpbuf2 = STRBUF_Create( 500, HEAPID_DENDOU_DEMO );

	wk->ah = ArchiveDataHandleOpen( ARC_DENDOU_DEMO, HEAPID_DENDOU_DEMO );

	wk->pme_ah = ArchiveDataHandleOpen( ARC_PM_EDIT, HEAPID_DENDOU_DEMO );

	// ポケモン取得
	PokeDataMake( wk );

	VramInit();
	BgInit( wk );
	ObjInit( wk );

	// サウンドデータロード
	Snd_DataSetByScene( SND_SCENE_DENDOU, SEQ_GS_E_DENDOUIRI, 1 );	//殿堂デモ曲再生
	Snd_DataSetByScene( SND_SCENE_SUB_DENDOU, 0, 0 );				//SE

	// フォントパレット
	SystemFontPaletteLoad( PALTYPE_MAIN_BG, 15 * 32, HEAPID_DENDOU_DEMO );

	wk->main_seq = MAINSEQ_1ST_INIT;
//	wk->main_seq = MAINSEQ_2ND_INIT;

	return PROC_RES_FINISH;
}

//--------------------------------------------------------------------------------------------
/**
 * プロセス終了
 *
 * @param	proc
 * @param	seq
 *
 * @return	PROC_RES_FINISH
 */
//--------------------------------------------------------------------------------------------
PROC_RESULT  DemoDendouPROC_Quit( PROC* proc, int* seq )
{
	DEMO_WORK * wk = PROC_GetWork( proc );

	ObjExit( wk );
	BgExit( wk );

	ArchiveDataHandleClose( wk->pme_ah );
	ArchiveDataHandleClose( wk->ah );

	STRBUF_Delete( wk->tmpbuf1 );
	STRBUF_Delete( wk->tmpbuf2 );
	WORDSET_Delete( wk->wset );
	MSGMAN_Delete( wk->mman );

	PROC_FreeWork( proc );
	sys_DeleteHeap( HEAPID_DENDOU_DEMO );

	return PROC_RES_FINISH;
}

//--------------------------------------------------------------------------------------------
/**
 * プロセスメイン
 *
 * @param	proc
 * @param	seq
 *
 * @retval	"PROC_RES_FINISH = 終了"
 * @retval	"PROC_RES_CONTINUE = 継続"
 */
//--------------------------------------------------------------------------------------------
PROC_RESULT  DemoDendouPROC_Main( PROC* proc, int* seq )
{
	DEMO_WORK * wk = PROC_GetWork( proc );

	wk->main_seq = MainSeqFunc[wk->main_seq]( wk );

	if( wk->main_seq == MAINSEQ_END ){
		return PROC_RES_FINISH;
	}

	ObjAnmMain( wk );

	return PROC_RES_CONTINUE;
}

//--------------------------------------------------------------------------------------------
/**
 * VRAM設定
 *
 * @param	none
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void VramInit(void)
{
	GF_Disp_SetBank( &VramTbl );
}

//--------------------------------------------------------------------------------------------
/**
 * VBLANKタスク
 *
 * @param	tcb
 * @param	work
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void VBlankFunc( TCB_PTR tcb, void * work )
{
	DEMO_WORK * wk = work;

	if( wk->vfunk != NULL ){
		pDendouDemoFunc func = wk->vfunk;
		if( func( wk ) == 0 ){
			wk->vfunk = NULL;
		}
	}

	GF_BGL_VBlankFunc( wk->bgl );

//	BOX2OBJ_AnmMain( syswk->app );
	CATS_Draw( wk->crp );
	CATS_RenderOamTrans();

	OS_SetIrqCheckFlag( OS_IE_V_BLANK );
}

//--------------------------------------------------------------------------------------------
/**
 * メインＯＢＪのＶＲＡＭにデータ転送
 *
 * @param	buf		転送データ
 * @param	adrs	転送位置
 * @param	siz		転送サイズ
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ObjVramTrans( void * buf, u32 adrs, u32 siz )
{
	DC_FlushRange( buf, siz );
	GX_LoadOBJ( buf, adrs, siz );
}

//--------------------------------------------------------------------------------------------
/**
 * メインＯＢＪのパレットＶＲＡＭにデータ転送
 *
 * @param	buf		転送データ
 * @param	adrs	転送位置
 * @param	siz		転送サイズ
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ObjPlttVramTrans( void * buf, u32 adrs, u32 siz )
{
	DC_FlushRange( buf, siz );
	GX_LoadOBJPltt( buf, adrs, siz );
}

//--------------------------------------------------------------------------------------------
/**
 * ＢＧ初期化
 *
 * @param	wk		画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void BgInit( DEMO_WORK * wk )
{
	wk->bgl = GF_BGL_BglIniAlloc( HEAPID_DENDOU_DEMO );

	// 下画面のバックグラウンドカラー設定
	GF_BGL_BackGroundColorSet( GF_BGL_FRAME0_S, 0 );
}

//--------------------------------------------------------------------------------------------
/**
 * ＢＧ削除
 *
 * @param	wk		画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void BgExit( DEMO_WORK * wk )
{
	sys_FreeMemoryEz( wk->bgl );
}

//--------------------------------------------------------------------------------------------
/**
 * ＯＢＪ初期化
 *
 * @param	wk		画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ObjInit( DEMO_WORK * wk )
{
	wk->csp = CATS_AllocMemory( HEAPID_DENDOU_DEMO );
	wk->crp = CATS_ResourceCreate( wk->csp );

	{
		TCATS_OAM_INIT	coi = {
			0, 128,
			0, 32,
			0, 128,
			0, 32,
		};
		TCATS_CHAR_MANAGER_MAKE ccmm = {
			1024,
			1024*64,
			1024*16,
			GX_OBJVRAMMODE_CHAR_1D_64K,
			GX_OBJVRAMMODE_CHAR_1D_64K
		};
		CATS_SystemInit( wk->csp, &coi, &ccmm, 32 );
	}
	{
		TCATS_RESOURCE_NUM_LIST	crnl = {
			CHR_ID_MAX, PAL_ID_MAX, CEL_ID_MAX, ANM_ID_MAX, 0, 0
		};
		CATS_ClactSetInit( wk->csp, wk->crp, OBJID_MAX );
		CATS_ResourceManagerInit( wk->csp, wk->crp, &crnl );
	}
	{
		CLACT_U_EASYRENDER_DATA * renddata = CATS_EasyRenderGet( wk->csp );
		CLACT_U_SetSubSurfaceMatrix( renddata, 0, 1024 * FX32_ONE );	// サブにＯＢＪを出さないので適当
	}
}

//--------------------------------------------------------------------------------------------
/**
 * ＯＢＪ解放
 *
 * @param	wk		画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ObjExit( DEMO_WORK * wk )
{
	CATS_ResourceDestructor_S( wk->csp, wk->crp );
	CATS_FreeMemory( wk->csp );
}

//--------------------------------------------------------------------------------------------
/**
 * ＯＢＪ削除
 *
 * @param	wk		画面ワーク
 * @param	id		OBJ ID
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ObjDel( DEMO_WORK * wk, u32 id )
{
	if( wk->cap[id] != NULL ){
		CATS_ActorPointerDelete_S( wk->cap[id] );
		wk->cap[id] = NULL;
	}
}

//--------------------------------------------------------------------------------------------
/**
 * ＯＢＪアニメメイン
 *
 * @param	wk		画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ObjAnmMain( DEMO_WORK * wk )
{
	u32	i;

	for( i=0; i<OBJID_MAX; i++ ){
		if( wk->cap[i] != NULL ){
			CATS_ObjectUpdateCap( wk->cap[i] );
		}
	}
}

//--------------------------------------------------------------------------------------------
/**
 * ＯＢＪアニメ設定
 *
 * @param	wk		画面ワーク
 * @param	id		OBJ ID
 * @param	anm		アニメ番号
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ObjAnmSet( DEMO_WORK * wk, u32 id, u32 anm )
{
	CATS_ObjectAnimeFrameSetCap( wk->cap[id], 0 );
	CATS_ObjectAnimeSeqSetCap( wk->cap[id], anm );
}

//--------------------------------------------------------------------------------------------
/**
 * フェードイン設定
 *
 * @param	wk		画面ワーク
 * @param	next	次のシーケンス
 *
 * @return	MAINSEQ_FADE_WAIT
 */
//--------------------------------------------------------------------------------------------
static int FadeInSet( DEMO_WORK * wk, int next )
{
	WIPE_SYS_Start(
		WIPE_PATTERN_WMS, WIPE_TYPE_FADEIN, WIPE_TYPE_FADEIN,
		WIPE_FADE_BLACK, WIPE_DEF_DIV, WIPE_DEF_SYNC, HEAPID_DENDOU_DEMO );
	wk->next_seq = next;
	return MAINSEQ_FADE_WAIT;
}

//--------------------------------------------------------------------------------------------
/**
 * フェードアウト設定
 *
 * @param	wk		画面ワーク
 * @param	next	次のシーケンス
 *
 * @return	MAINSEQ_FADE_WAIT
 */
//--------------------------------------------------------------------------------------------
static int FadeOutSet( DEMO_WORK * wk, int next )
{
	WIPE_SYS_Start(
		WIPE_PATTERN_WMS, WIPE_TYPE_FADEOUT, WIPE_TYPE_FADEOUT,
		WIPE_FADE_BLACK, WIPE_DEF_DIV, WIPE_DEF_SYNC, HEAPID_DENDOU_DEMO );
	wk->next_seq = next;
	return MAINSEQ_FADE_WAIT;
}

//--------------------------------------------------------------------------------------------
/**
 * VBLANK処理設定
 *
 * @param	wk		画面ワーク
 * @param	func	関数ポインタ
 * @param	next	次のシーケンス
 *
 * @return	MAINSEQ_VFUNC
 */
//--------------------------------------------------------------------------------------------
static int VFuncSet( DEMO_WORK * wk, void * func, int next )
{
	wk->next_seq = next;
	wk->vcnt  = 0;
	wk->vseq  = 0;
	wk->vfunk = func;
	return MAINSEQ_VFUNC;
}

//--------------------------------------------------------------------------------------------
/**
 * メインシーケンス：フェード待ち
 *
 * @param	wk		画面ワーク
 *
 * @return	次のシーケンス
 */
//--------------------------------------------------------------------------------------------
static int MainSeq_FadeWait( DEMO_WORK * wk )
{
	if( WIPE_SYS_EndCheck() == TRUE ){
		return wk->next_seq;
	}
	return MAINSEQ_FADE_WAIT;
}

//--------------------------------------------------------------------------------------------
/**
 * メインシーケンス：VBLANK終了待ち
 *
 * @param	wk		画面ワーク
 *
 * @return	次のシーケンス
 */
//--------------------------------------------------------------------------------------------
static int MainSeq_VFunc( DEMO_WORK * wk )
{
	if( wk->vfunk == NULL ){
		return wk->next_seq;
	}
	return MAINSEQ_VFUNC;
}

//--------------------------------------------------------------------------------------------
/**
 * メインシーケンス：1stシーン初期化
 *
 * @param	wk		画面ワーク
 *
 * @return	次のシーケンス
 */
//--------------------------------------------------------------------------------------------
static int MainSeq_1stInit( DEMO_WORK * wk )
{
	Scene01BgInit( wk );
	Scene01BmpInit( wk );
	Scene01BgGraphicLoad( wk );

	wk->sub_seq = 0;
	wk->mv_poke = 0;

	wk->vtask = VIntrTCB_Add( VBlankFunc, wk, 0 );

	return FadeInSet( wk, MAINSEQ_1ST_MAIN );
}

//--------------------------------------------------------------------------------------------
/**
 * メインシーケンス：1stシーンメイン
 *
 * @param	wk		画面ワーク
 *
 * @return	次のシーケンス
 */
//--------------------------------------------------------------------------------------------
static int MainSeq_1stMain( DEMO_WORK * wk )
{
	switch( wk->sub_seq ){
	case 0:		// 準備
		Scene01_MoveInit( wk );
		wk->sub_seq++;
		break;

	case 1:		// 動作へ
		wk->sub_seq++;
		if( ( wk->mv_poke & 1 ) == 0 ){
			VFuncSet( wk, VFunc1stSceneLeft, MAINSEQ_1ST_MAIN );
			break;
		}else{
			VFuncSet( wk, VFunc1stSceneRight, MAINSEQ_1ST_MAIN );
			break;
		}
		break;

	case 2:		// メイン
		if( wk->vfunk == NULL ){
			wk->sub_seq++;
		}else{
			if( wk->b_anm_flg == 1 ){
				PokeAnimTaskSet( wk, wk->mv_poke, OBJID_1ST_POKE_BACK, TRUE, PARA_BACK );
				wk->b_anm_flg = 0;
			}
			if( wk->f_anm_flg == 1 ){
				PokeAnimTaskSet( wk, wk->mv_poke, OBJID_1ST_POKE, TRUE, PARA_FRONT );
				wk->f_anm_flg = 0;
			}
		}
		break;

	case 3:		// 判定
		ObjExit1st( wk );
		wk->mv_poke++;
		if( wk->pokeCount == wk->mv_poke ){
			wk->sub_seq++;
		}else{
			wk->sub_seq = 0;
		}
		break;

	case 4:
		return FadeOutSet( wk, MAINSEQ_1ST_END );
	}
	return MAINSEQ_1ST_MAIN;
}

//--------------------------------------------------------------------------------------------
/**
 * メインシーケンス：1stシーン終了
 *
 * @param	wk		画面ワーク
 *
 * @return	次のシーケンス
 */
//--------------------------------------------------------------------------------------------
static int MainSeq_1stEnd( DEMO_WORK * wk )
{
	TCB_Delete( wk->vtask );

	Scene01BmpExit( wk );
	Scene01BgExit( wk );

	return MAINSEQ_2ND_INIT;
}

//--------------------------------------------------------------------------------------------
/**
 * メインシーケンス：2ndシーン初期化
 *
 * @param	wk		画面ワーク
 *
 * @return	次のシーケンス
 */
//--------------------------------------------------------------------------------------------
static int MainSeq_2ndInit( DEMO_WORK * wk )
{
	wk->mv_poke = 0;
	wk->sub_seq = 0;

	Scene02BgInit( wk );
	Scene02BgGraphicLoad( wk );
	Scene02BmpInit( wk );
	Scene02ObjInit( wk );

	Scene02Init3D( wk );

	wk->vtask = VIntrTCB_Add( Scene02VBlankFunc, wk, S2_TASKPRI_MAIN );

	return FadeInSet( wk, MAINSEQ_2ND_MAIN );
}

//--------------------------------------------------------------------------------------------
/**
 * メインシーケンス：2ndシーンメイン
 *
 * @param	wk		画面ワーク
 *
 * @return	次のシーケンス
 */
//--------------------------------------------------------------------------------------------
static int MainSeq_2ndMain( DEMO_WORK * wk )
{
	switch( wk->sub_seq ){
	case 0:
		wk->sub_seq++;
		VFuncSet( wk, VFunc2ndSceneMain, MAINSEQ_2ND_MAIN );
		break;
	case 1:
		if( wk->vfunk == NULL ){
			wk->sub_seq++;
		}
		if( wk->eff_flg == 1 ){
			wk->lightTask = CreateLightCtrlTask( wk );
			AddLightTask( wk->lightTask, -FX16_CONST(0.714f), FX32_CONST(20) );
			AddLightTask( wk->lightTask, -FX16_CONST(0.429f), FX32_CONST(60) );
			AddLightTask( wk->lightTask, -FX16_CONST(0.143f), FX32_CONST(40) );
			AddLightTask( wk->lightTask,  FX16_CONST(0.143f), FX32_CONST(140) );
			AddLightTask( wk->lightTask,  FX16_CONST(0.429f), FX32_CONST(120) );
			AddLightTask( wk->lightTask,  FX16_CONST(0.714f), FX32_CONST(160) );

			wk->confettiTask = CreateConfettiTask( wk );
			StartConfettiDraw( wk->confettiTask );

			GF_Disp_GX_VisibleControl( GX_PLANEMASK_BG1, VISIBLE_ON );
			GF_Disp_GX_VisibleControl( GX_PLANEMASK_BG2, VISIBLE_ON );
			GF_Disp_GX_VisibleControl( GX_PLANEMASK_BG3, VISIBLE_ON );

			CATS_ObjectEnableCap( wk->cap[OBJID_2ND_PLAYER], 1 );
			CATS_ObjectEnableCap( wk->cap[OBJID_2ND_PLAYER_S], 1 );

			{
				u32	i;

//				for( i=0; i<TEMOTI_POKEMAX; i++ ){
				for( i=0; i<wk->pokeCount; i++ ){
					PokePaletteSet( wk, i, OBJID_2ND_POKE1+i );
					CATS_ObjectScaleSetCap( wk->cap[OBJID_2ND_POKE1+i], 1.0, 1.0 );
					CATS_ObjectEnableCap( wk->cap[OBJID_2ND_POKE_S1+i], 1 );
					CATS_ObjectObjModeSetCap( wk->cap[OBJID_2ND_POKE1+i], GX_OAM_MODE_NORMAL );
					CATS_ObjectObjModeSetCap( wk->cap[OBJID_2ND_POKE_S1+i], GX_OAM_MODE_XLU );
				}
			}

			wk->eff_flg = 0;
		}
		if( wk->fade_flg == 1 ){
			Scene02FadeSet( wk );
			Snd_SePlay( SEQ_SE_GS_DENDOUIRI_FLASH );
			Snd_SePlay( SEQ_SE_GS_DENDOUIRI_KANSEI );
			wk->fade_flg = 0;
		}
		if( wk->fo_flg == 1 ){
			Scene02FadeOutSet( wk );
			wk->fo_flg = 0;
		}
		break;
	case 2:
		wk->sub_seq = 0;
		return MAINSEQ_2ND_END;
	}

	return MAINSEQ_2ND_MAIN;
}

//--------------------------------------------------------------------------------------------
/**
 * メインシーケンス：2ndシーン終了
 *
 * @param	wk		画面ワーク
 *
 * @return	次のシーケンス
 */
//--------------------------------------------------------------------------------------------
static int MainSeq_2ndEnd( DEMO_WORK * wk )
{
	switch( wk->sub_seq ){
	case 0:
		TCB_Delete( wk->vtask );
		DeleteConfettiTask( wk->confettiTask );
		DeleteLightCtrlTask( wk->lightTask );
		wk->sub_seq++;
		break;
	case 1:
		if( WaitLightTaskDelete() == TRUE ){
			wk->sub_seq++;
		}
		break;

	case 2:
		Scene02Exit3D( wk );

		Scene02ObjExit( wk );
		Scene02BmpExit( wk );
		Scene02BgExit( wk );
		return MAINSEQ_END;
	}

	return MAINSEQ_2ND_END;
}

//--------------------------------------------------------------------------------------------
/**
 * ポケモンＯＢＪ移動
 *
 * @param	cap		セルアクターのポインタ
 * @param	dat		移動データ
 * @param	frame	移動終了までのフレーム数
 * @param	cnt		現在のプレーム数
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void PokeMove( CATS_ACT_PTR cap, const S2_POKE_MOVE_DATA * dat, u32 frame, u32 cnt )
{
	if( cnt == 0 ){
		CATS_ObjectPosSetCap( cap, dat->init_x, dat->init_y );
		CATS_ObjectScaleSetCap( cap, dat->init_scale, dat->init_scale );
	}else if( cnt == frame ){
		CATS_ObjectPosSetCap( cap, dat->end_x, dat->end_y );
		CATS_ObjectScaleSetCap( cap, dat->end_scale, dat->end_scale );
	}else{
		s16	x, y;
		f32	scale;

		x = MV_CALC( dat->init_x, dat->end_x, frame, cnt );
		if( dat->init_x > dat->end_x ){
			x = dat->init_x - x;
		}else{
			x = dat->init_x + x;
		}

		y = MV_CALC( dat->init_y, dat->end_y, frame, cnt );
		if( dat->init_y > dat->end_y ){
			y = dat->init_y - y;
		}else{
			y = dat->init_y + y;
		}

		CATS_ObjectPosSetCap( cap, x, y );

		scale = dat->init_scale + ( ( ( dat->end_scale - dat->init_scale ) / frame ) * cnt );
		CATS_ObjectScaleSetCap( cap, scale, scale );
	}
}

//--------------------------------------------------------------------------------------------
/**
 * ポケモングラフィックリソース読み込み
 *
 * @param	wk		画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void PokeGraResLoad( DEMO_WORK * wk )
{
	ARCHANDLE * ah;

	ah = ArchiveDataHandleOpen( ARC_BATT_OBJ, HEAPID_DENDOU_DEMO );

	// 正面用
	CATS_LoadResourceCharArcH(
		wk->csp, wk->crp, ah, POKE_OAM_NCGR, 0, NNS_G2D_VRAM_TYPE_2DMAIN, CHR_ID_POKEGRA1 );
	CATS_LoadResourceCellArcH( wk->csp, wk->crp, ah, POKE_OAM_NCER, 0, CEL_ID_POKEGRA1 );
	CATS_LoadResourceCellAnmArcH( wk->csp, wk->crp, ah, POKE_OAM_NANR, 0, ANM_ID_POKEGRA1 );
	CATS_LoadResourcePlttArcH(
		wk->csp, wk->crp, ah, POKE_OAM_NCLR, 0, 1, NNS_G2D_VRAM_TYPE_2DMAIN, PAL_ID_POKEGRA1 );
	CATS_LoadResourcePlttArcH(
		wk->csp, wk->crp, ah, POKE_OAM_NCLR, 0, 1, NNS_G2D_VRAM_TYPE_2DMAIN, PAL_ID_POKEGRA2 );

	// 背面用
	CATS_LoadResourceCharArcH(
		wk->csp, wk->crp, ah, POKE_OAM_NCGR, 0, NNS_G2D_VRAM_TYPE_2DMAIN, CHR_ID_POKEGRA2 );
	CATS_LoadResourceCellArcH( wk->csp, wk->crp, ah, POKE_OAM_NCER, 0, CEL_ID_POKEGRA2 );
	CATS_LoadResourceCellAnmArcH( wk->csp, wk->crp, ah, POKE_OAM_NANR, 0, ANM_ID_POKEGRA2 );
	CATS_LoadResourcePlttArcH(
		wk->csp, wk->crp, ah, POKE_OAM_NCLR, 0, 1, NNS_G2D_VRAM_TYPE_2DMAIN, PAL_ID_POKEGRA3 );
	CATS_LoadResourcePlttArcH(
		wk->csp, wk->crp, ah, POKE_OAM_NCLR, 0, 1, NNS_G2D_VRAM_TYPE_2DMAIN, PAL_ID_POKEGRA4 );

	ArchiveDataHandleClose( ah );
}

//--------------------------------------------------------------------------------------------
/**
 * ポケモングラフィックリソース解放
 *
 * @param	wk		画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void PokeGraResFree( DEMO_WORK * wk )
{
	CATS_FreeResourcePltt( wk->crp, PAL_ID_POKEGRA1 );
	CATS_FreeResourcePltt( wk->crp, PAL_ID_POKEGRA2 );
	CATS_FreeResourcePltt( wk->crp, PAL_ID_POKEGRA3 );
	CATS_FreeResourcePltt( wk->crp, PAL_ID_POKEGRA4 );

	CATS_FreeResourceChar( wk->crp, CHR_ID_POKEGRA1 );
	CATS_FreeResourceCell( wk->crp, CEL_ID_POKEGRA1 );
	CATS_FreeResourceCellAnm( wk->crp, ANM_ID_POKEGRA1 );

	CATS_FreeResourceChar( wk->crp, CHR_ID_POKEGRA2 );
	CATS_FreeResourceCell( wk->crp, CEL_ID_POKEGRA2 );
	CATS_FreeResourceCellAnm( wk->crp, ANM_ID_POKEGRA2 );
}

//--------------------------------------------------------------------------------------------
/**
 * ポケモングラフィック切り替え
 *
 * @param	wk		画面ワーク
 * @param	pd		ポケモンデータ
 * @param	dir		向き（正面・背面）
 * @param	id		OBJ番号
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void PokeGraChange( DEMO_WORK * wk, POKE_DATA * pd, u8 dir, u32 id )
{
	SOFT_SPRITE_ARC  ssa;
	NNSG2dImageProxy * ipc;
	NNSG2dImagePaletteProxy * ipp;
	u8 * buf;
	u32	cgx;
	u32	pal;
	CHANGES_INTO_DATA_RECT rect[] =
	{
		{ POKE_TEX_X, POKE_TEX_Y, POKE_TEX_W, POKE_TEX_H },
		{ POKE_TEX_X+POKE_TEX_W, POKE_TEX_Y, POKE_TEX_W, POKE_TEX_H },
	};

	PokeGraArcDataGetPP( &ssa, pd->pp, dir );

	if( dir == PARA_FRONT ){
		buf = &pd->cgxBuf[0][0];
	}else{
		buf = &pd->cgxBuf[1][0];
	}

	ipc = CLACT_ImageProxyGet( wk->cap[id]->act );
	cgx = NNS_G2dGetImageLocation( ipc, NNS_G2D_VRAM_TYPE_2DMAIN );

	ObjVramTrans( buf, cgx, POKEGRA_TEX_SIZE );

	ipp = CLACT_PaletteProxyGet( wk->cap[id]->act );
	pal = NNS_G2dGetImagePaletteLocation( ipp, NNS_G2D_VRAM_TYPE_2DMAIN );

	ArcUtil_PalSet(
		ssa.arc_no, ssa.index_pal, PALTYPE_MAIN_OBJ, pal, POKEGRA_PAL_SIZE, HEAPID_DENDOU_DEMO );
}

//--------------------------------------------------------------------------------------------
/**
 * ポケモングラフィックに影・シルエットのカラーをセット
 *
 * @param	wk		画面ワーク
 * @param	id		OBJ番号
 * @param	col		カラー
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void PokeShadowColSet( DEMO_WORK * wk, u32 id, u32 col )
{
	NNSG2dImagePaletteProxy * ipp;
	const u16 * dat;
	u32	pal;

	ipp = CLACT_PaletteProxyGet( wk->cap[id]->act );
	pal = NNS_G2dGetImagePaletteLocation( ipp, NNS_G2D_VRAM_TYPE_2DMAIN );

	switch( col ){
	case SHADOW_COL_BLACK:
		dat = ShadowBlack;
		break;
	case SHADOW_COL_WHITE:
		dat = ShadowWhite;
		break;
	case SHADOW_COL_RED:
		dat = ShadowRed;
		break;
	}
	ObjPlttVramTrans( (void *)dat, pal, POKEGRA_PAL_SIZE );
}

//--------------------------------------------------------------------------------------------
/**
 * ポケモングラフィックのパレットを取得
 *
 * @param	wk		画面ワーク
 * @param	pokeID	ポケモン位置
 * @param	objID	ＯＢＪ番号
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void PokePaletteGet( DEMO_WORK * wk, u32 pokeID, u32 objID )
{
	POKE_DATA * pd;
	NNSG2dImagePaletteProxy * ipp;
	u16 * vrm;
	u32	pal;

	pd = &wk->poke[pokeID];

	ipp = CLACT_PaletteProxyGet( wk->cap[objID]->act );
	pal = NNS_G2dGetImagePaletteLocation( ipp, NNS_G2D_VRAM_TYPE_2DMAIN );

	vrm = (u16 *)GF_MMAP_MainObjPlttAddr();

	MI_CpuCopy8( &vrm[pal/2], pd->palBuf, 0x20 );
}

//--------------------------------------------------------------------------------------------
/**
 * ポケモングラフィックにパレットをセット
 *
 * @param	wk		画面ワーク
 * @param	pokeID	ポケモン位置
 * @param	objID	ＯＢＪ番号
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void PokePaletteSet( DEMO_WORK * wk, u32 pokeID, u32 objID )
{
	POKE_DATA * pd;
	NNSG2dImagePaletteProxy * ipp;
	u32	pal;

	pd = &wk->poke[pokeID];

	ipp = CLACT_PaletteProxyGet( wk->cap[objID]->act );
	pal = NNS_G2dGetImagePaletteLocation( ipp, NNS_G2D_VRAM_TYPE_2DMAIN );

	ObjPlttVramTrans( (void *)pd->palBuf, pal, POKEGRA_PAL_SIZE );
}


//============================================================================================
//	連れ歩き
//============================================================================================

//--------------------------------------------------------------------------------------------
/**
 * 連れ歩きポケモンのリソース読み込み
 *
 * @param	wk		画面ワーク
 * @param	pd		ポケモンデータ
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void PokeWalkResLoad( DEMO_WORK * wk, POKE_DATA * pd )
{
	if( pd->info.BigSize ){
		CATS_LoadResourceCharArcH(
			wk->csp, wk->crp, wk->ah,
			NARC_dendou_demo_pw_obj_64_lz_NCGR, 1, NNS_G2D_VRAM_TYPE_2DMAIN, CHR_ID_POKEWALK1 );
		CATS_LoadResourceCellArcH(
			wk->csp, wk->crp, wk->ah,
			NARC_dendou_demo_pw_obj_64_lz_NCER, 1, CEL_ID_POKEWALK1 );
		CATS_LoadResourceCellAnmArcH(
			wk->csp, wk->crp, wk->ah,
			NARC_dendou_demo_pw_obj_64_lz_NANR, 1, ANM_ID_POKEWALK1 );
	}else{
		CATS_LoadResourceCharArcH(
			wk->csp, wk->crp, wk->ah,
			NARC_dendou_demo_pw_obj_32_lz_NCGR, 1, NNS_G2D_VRAM_TYPE_2DMAIN, CHR_ID_POKEWALK1 );
		CATS_LoadResourceCellArcH(
			wk->csp, wk->crp, wk->ah,
			NARC_dendou_demo_pw_obj_32_lz_NCER, 1, CEL_ID_POKEWALK1 );
		CATS_LoadResourceCellAnmArcH(
			wk->csp, wk->crp, wk->ah,
			NARC_dendou_demo_pw_obj_32_lz_NANR, 1, ANM_ID_POKEWALK1 );
	}

	CATS_LoadResourcePlttArcH(
		wk->csp, wk->crp, wk->ah,
		NARC_dendou_demo_pw_obj_64_NCLR, 0, 1, NNS_G2D_VRAM_TYPE_2DMAIN, PAL_ID_POKEWALK1 );
	CATS_LoadResourcePlttArcH(
		wk->csp, wk->crp, wk->ah,
		NARC_dendou_demo_pw_obj_64_NCLR, 0, 1, NNS_G2D_VRAM_TYPE_2DMAIN, PAL_ID_POKEWALK2 );
}

//--------------------------------------------------------------------------------------------
/**
 * 連れ歩きポケモンのリソース解放
 *
 * @param	wk		画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void PokeWalkResFree( DEMO_WORK * wk )
{
	CATS_FreeResourcePltt( wk->crp, PAL_ID_POKEWALK1 );
	CATS_FreeResourcePltt( wk->crp, PAL_ID_POKEWALK2 );
	CATS_FreeResourceChar( wk->crp, CHR_ID_POKEWALK1 );
	CATS_FreeResourceCell( wk->crp, CEL_ID_POKEWALK1 );
	CATS_FreeResourceCellAnm( wk->crp, ANM_ID_POKEWALK1 );
}

//--------------------------------------------------------------------------------------------
/**
 * 連れ歩きポケモン切り替え
 *
 * @param	wk		画面ワーク
 * @param	pd		ポケモンデータ
 * @param	id		OBJ番号
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void PokeWalkChange( DEMO_WORK * wk, POKE_DATA * pd, u32 id )
{
	NNSG2dImageProxy * ipc;
	NNSG2dImagePaletteProxy * ipp;
	NNSG3dResTex * tex;
	void * file;
	u8 * raw;
	void * buf;
	int	arc;
	u32	pal;
	u32	cgx;
	u32	cgx_siz;
	u8	cgx_sx, cgx_sy;
	u8	i;

	ipc = CLACT_ImageProxyGet( wk->cap[id]->act );
	cgx = NNS_G2dGetImageLocation( ipc, NNS_G2D_VRAM_TYPE_2DMAIN );

	if( pd->info.BigSize ){
		cgx_sx = 8;
		cgx_sy = 8;
	}else{
		cgx_sx = 4;
		cgx_sy = 4;
	}
	cgx_siz = 0x20 * cgx_sx * cgx_sy;

	// アーカイブインデックス取得
	arc = GetMonsArcIdx( pd->mons, pd->frm, pd->sex );
	// 連れ歩きポケモンのテクスチャを読み込んでくる
	file = ArchiveDataLoadMalloc( ARC_MMODEL, arc, HEAPID_DENDOU_DEMO );
	// テクスチャファイルを取得
	tex = NNS_G3dGetTex( file );
	// テクスチャロウデータ取得
	raw = (u8 *)tex + tex->texInfo.ofsTex;

	buf = sys_AllocMemory( HEAPID_DENDOU_DEMO, cgx_siz );

	for( i=0; i<8; i++ ){
		// キャラデータ用のバッファにテクスチャのロウデータを1D変換して格納
		ChangesInto_RawData_1D_from_2D( &raw[cgx_siz*i], cgx_sx, 0, 0, cgx_sx, cgx_sy, buf );
		ObjVramTrans( buf, cgx+(cgx_siz*i), cgx_siz );
/*
		{
			u8 *data;
			data = (u8 *)chara_data->pRawData;
			//抜き色検索用にテクスチャをダミーロウデータに転送しておく(VRAM転送のための用途も含む)
			MI_CpuCopyFast(cnt_ptr->CharTempBuff,&data[trans_size*i],trans_size);
		}
*/
	}

	sys_FreeMemoryEz( buf );


	ipp = CLACT_PaletteProxyGet( wk->cap[id]->act );
	pal = NNS_G2dGetImagePaletteLocation( ipp, NNS_G2D_VRAM_TYPE_2DMAIN );

	// パレットロウデータ取得
	raw = (u8 *)tex + tex->plttInfo.ofsPlttData;
	// レアかどうかでオフセット変更
	if( PokeRareGet( pd->pp ) == TRUE ){
		raw = &raw[POKEWALK_PAL_SIZE];
	}
	ObjPlttVramTrans( raw, pal, POKEWALK_PAL_SIZE );

	sys_FreeMemoryEz( file );
}


//============================================================================================
//	シーン１
//============================================================================================

//--------------------------------------------------------------------------------------------
/**
 * シーン１：ＢＧ初期化
 *
 * @param	wk		画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void Scene01BgInit( DEMO_WORK * wk )
{
	{	// BG SYSTEM
		GF_BGL_SYS_HEADER sysh = {
			GX_DISPMODE_GRAPHICS, GX_BGMODE_0, GX_BGMODE_0, GX_BG0_AS_2D,
		};
		GF_BGL_InitBG( &sysh );
	}

	{	// メイン画面：文字
		GF_BGL_BGCNT_HEADER cnth= {
			0, 0, 0x2000, 0, GF_BGL_SCRSIZ_512x512, GX_BG_COLORMODE_16,
			GX_BG_SCRBASE_0xe000, GX_BG_CHARBASE_0x18000, GX_BG_EXTPLTT_01,
			0, 0, 0, FALSE
		};
		GF_BGL_BGControlSet( wk->bgl, GF_BGL_FRAME0_M, &cnth, GF_BGL_MODE_TEXT );
		GF_BGL_ScrClear( wk->bgl, GF_BGL_FRAME0_M );
		GF_BGL_ClearCharSet( GF_BGL_FRAME0_M, 0x20, 0, HEAPID_DENDOU_DEMO );
	}
	{	// メイン画面：ワイプ１
		GF_BGL_BGCNT_HEADER cnth= {
			0, 0, 0x2000, 0, GF_BGL_SCRSIZ_512x512, GX_BG_COLORMODE_16,
			GX_BG_SCRBASE_0xc000, GX_BG_CHARBASE_0x10000, GX_BG_EXTPLTT_01,
			1, 0, 0, FALSE
		};
		GF_BGL_BGControlSet( wk->bgl, GF_BGL_FRAME1_M, &cnth, GF_BGL_MODE_TEXT );
	}
	{	// メイン画面：ワイプ２
		GF_BGL_BGCNT_HEADER cnth= {
			0, 0, 0x2000, 0, GF_BGL_SCRSIZ_512x512, GX_BG_COLORMODE_16,
			GX_BG_SCRBASE_0xa000, GX_BG_CHARBASE_0x10000, GX_BG_EXTPLTT_01,
			2, 0, 0, FALSE
		};
		GF_BGL_BGControlSet( wk->bgl, GF_BGL_FRAME2_M, &cnth, GF_BGL_MODE_TEXT );
	}
	{	// メイン画面：背景
		GF_BGL_BGCNT_HEADER cnth= {
			0, 0, 0x2000, 0, GF_BGL_SCRSIZ_512x512, GX_BG_COLORMODE_16,
			GX_BG_SCRBASE_0x8000, GX_BG_CHARBASE_0x10000, GX_BG_EXTPLTT_01,
			3, 0, 0, FALSE
		};
		GF_BGL_BGControlSet( wk->bgl, GF_BGL_FRAME3_M, &cnth, GF_BGL_MODE_TEXT );
	}
}

//--------------------------------------------------------------------------------------------
/**
 * シーン１：ＢＧ削除
 *
 * @param	wk		画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void Scene01BgExit( DEMO_WORK * wk )
{
	GF_BGL_BGControlExit( wk->bgl, GF_BGL_FRAME3_M );
	GF_BGL_BGControlExit( wk->bgl, GF_BGL_FRAME2_M );
	GF_BGL_BGControlExit( wk->bgl, GF_BGL_FRAME1_M );
	GF_BGL_BGControlExit( wk->bgl, GF_BGL_FRAME0_M );
}

//--------------------------------------------------------------------------------------------
/**
 * シーン１：ＢＧグラフィック読み込み
 *
 * @param	wk		画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void Scene01BgGraphicLoad( DEMO_WORK * wk )
{
	ArcUtil_HDL_ScrnSet(
		wk->ah, NARC_dendou_demo_scene1_bg01_lz_NSCR,
		wk->bgl, GF_BGL_FRAME1_M, 0, 0, TRUE, HEAPID_DENDOU_DEMO );
	ArcUtil_HDL_ScrnSet(
		wk->ah, NARC_dendou_demo_scene1_bg02_lz_NSCR,
		wk->bgl, GF_BGL_FRAME2_M, 0, 0, TRUE, HEAPID_DENDOU_DEMO );
	ArcUtil_HDL_ScrnSet(
		wk->ah, NARC_dendou_demo_scene1_bg03_lz_NSCR,
		wk->bgl, GF_BGL_FRAME3_M, 0, 0, TRUE, HEAPID_DENDOU_DEMO );

	ArcUtil_HDL_BgCharSet(
		wk->ah, NARC_dendou_demo_scene1_bg_lz_NCGR,
		wk->bgl, GF_BGL_FRAME1_M, 0, 0, TRUE, HEAPID_DENDOU_DEMO );

	ArcUtil_HDL_PalSet(
		wk->ah, NARC_dendou_demo_scene1_bg_NCLR, PALTYPE_MAIN_BG, 0, 0x20, HEAPID_DENDOU_DEMO );
}

#define	S1_DENDOU_STR_PX	( 128 )		//「でんどういり〜」表示基準Ｘ座標

//--------------------------------------------------------------------------------------------
/**
 * シーン１：ＢＭＰ初期化
 *
 * @param	wk		画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void Scene01BmpInit( DEMO_WORK * wk )
{
	u32	i;

	for( i=0; i<S1_BMPWIN_MAX; i++ ){
		GF_BGL_BmpWinAddEx( wk->bgl, &wk->win[i], &Scene01BmpWinData[i] );
	}

	//「でんどういり〜」
	GF_BGL_BmpWinDataFill( &wk->win[S1_BMPWIN_TITLE], 0 );
	MSGMAN_GetString( wk->mman, str_dendemo_cong0, wk->tmpbuf1 );
	GF_STR_PrintColor(
		&wk->win[S1_BMPWIN_TITLE], FONT_SYSTEM, wk->tmpbuf1,
		S1_DENDOU_STR_PX - ( FontProc_GetPrintStrWidth(FONT_SYSTEM,wk->tmpbuf1,0) / 2 ), 0,
		MSG_NO_PUT, FCOL_WN15, NULL );
	GF_BGL_BmpWinCgxOn( &wk->win[S1_BMPWIN_TITLE] );
}

//--------------------------------------------------------------------------------------------
/**
 * シーン１：ＢＭＰ削除
 *
 * @param	wk		画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void Scene01BmpExit( DEMO_WORK * wk )
{
	u32	i;

	for( i=0; i<S1_BMPWIN_MAX; i++ ){
		GF_BGL_BmpWinDel( &wk->win[i] );
	}
}

//--------------------------------------------------------------------------------------------
/**
 * シーン１：ポケモンデータ設定
 *
 * @param	wk		画面ワーク
 * @param	num		ポケモン位置
 * @param	id		BMPWINの番号
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void Scene01PokeDataSet( DEMO_WORK * wk, u32 num, u32 id )
{
	GF_BGL_BMPWIN * win;
	POKE_DATA * pd;
	POKEMON_PARAM * pp;
	POKEMON_PASO_PARAM * ppp;
	POKE_MEET_PATTERN	ptn;
	u8	y, m, d;

	win = &wk->win[id];

	pd  = &wk->poke[num];
	pp  = wk->poke[num].pp;
	ppp = PPPPointerGet( pp );

	// ニックネーム
	GF_BGL_BmpWinDataFill( &win[0], 0 );
	MSGMAN_GetString( wk->mman, str_dendemo_poke_nickname, wk->tmpbuf1 );
	WORDSET_RegisterPokeNickName( wk->wset, 0, ppp );
	WORDSET_ExpandStr( wk->wset, wk->tmpbuf2, wk->tmpbuf1 );
	GF_STR_PrintColor( &win[0], FONT_SYSTEM, wk->tmpbuf2, 2, 0, MSG_NO_PUT, FCOL_WN15, NULL );
	GF_BGL_BmpWinCgxOn( &win[0] );

	// パラメータ
	GF_BGL_BmpWinDataFill( &win[1], 0 );
	// 種族名
	if( pd->sex == PARA_UNK || pd->sex_put == 0 ){
		MSGMAN_GetString( wk->mman, str_dendemo_poke_neutral, wk->tmpbuf1 );
	}else if( pd->sex == PARA_MALE ){
		MSGMAN_GetString( wk->mman, str_dendemo_poke_male, wk->tmpbuf1 );
	}else if( pd->sex == PARA_FEMALE ){
		MSGMAN_GetString( wk->mman, str_dendemo_poke_female, wk->tmpbuf1 );
	}else{
		MSGMAN_GetString( wk->mman, str_dendemo_poke_neutral, wk->tmpbuf1 );
	}
	WORDSET_RegisterPokeMonsName( wk->wset, 0, ppp );
	WORDSET_ExpandStr( wk->wset, wk->tmpbuf2, wk->tmpbuf1 );
	GF_STR_PrintColor( &win[1], FONT_SYSTEM, wk->tmpbuf2, 2, 0, MSG_NO_PUT, FCOL_WN15, NULL );
	// レベル
	MSGMAN_GetString( wk->mman, str_dendemo_poke_nickname0002, wk->tmpbuf1 );
	WORDSET_RegisterNumber(
		wk->wset, 0, pd->lv, 3, NUMBER_DISPTYPE_LEFT, NUMBER_CODETYPE_DEFAULT );
	WORDSET_ExpandStr( wk->wset, wk->tmpbuf2, wk->tmpbuf1 );
	GF_STR_PrintColor( &win[1], FONT_SYSTEM, wk->tmpbuf2, 2, 16, MSG_NO_PUT, FCOL_WN15, NULL );
	GF_BGL_BmpWinCgxOn( &win[1] );

	// メモ
	GF_BGL_BmpWinDataFill( &win[2], 0 );
	// 親
	MSGMAN_GetString( wk->mman, str_dendemo_player0, wk->tmpbuf1 );
	WORDSET_RegisterPokeOyaName( wk->wset, 0, ppp );
	WORDSET_ExpandStr( wk->wset, wk->tmpbuf2, wk->tmpbuf1 );
	GF_STR_PrintColor( &win[2], FONT_SYSTEM, wk->tmpbuf2, 2, 0, MSG_NO_PUT, FCOL_WN15, NULL );
	// 場所
	switch( GetPokeMeetPattern(wk,pp,wk->prm->player) ){
	case POKE_MEET_CATCH:		///< ゲーム内で捕獲した
		MSGMAN_GetString( wk->mman, str_dendemo_meet0, wk->tmpbuf1 );
		WORDSET_RegisterPlaceName( wk->wset, 0, pd->birth );
		WORDSET_ExpandStr( wk->wset, wk->tmpbuf2, wk->tmpbuf1 );
		break;
	case POKE_MEET_BORN:		///< 自分でタマゴを孵した
		MSGMAN_GetString( wk->mman, str_dendemo_meet1, wk->tmpbuf1 );
		WORDSET_RegisterPlaceName( wk->wset, 0, pd->birth );
		WORDSET_ExpandStr( wk->wset, wk->tmpbuf2, wk->tmpbuf1 );
		break;
	case POKE_MEET_TRADE:		///< つうしん交換で
		MSGMAN_GetString( wk->mman, str_dendemo_meet2, wk->tmpbuf2 );
		break;
	case POKE_MEET_KANTOU:		///< 赤緑から来た
		MSGMAN_GetString( wk->mman, str_dendemo_meet3, wk->tmpbuf2 );
		break;
	case POKE_MEET_HOUEN:		///< ルビサファエメらから来た
		MSGMAN_GetString( wk->mman, str_dendemo_meet4, wk->tmpbuf2 );
		break;
	case POKE_MEET_SHINOU:		///< D/P/PL
		MSGMAN_GetString( wk->mman, str_dendemo_meet7, wk->tmpbuf2 );
		break;
	case POKE_MEET_SOMEWHERE:	///< どこかとおいばしょ（コロシアム専用）
		MSGMAN_GetString( wk->mman, str_dendemo_meet5, wk->tmpbuf2 );
		break;
	case POKE_MEET_OTHER:		///< 後は全部うんめい的な出会い
		MSGMAN_GetString( wk->mman, str_dendemo_meet6, wk->tmpbuf2 );
		break;
	case POKE_MEET_TSUBOTSUBO:	///< イベントポケモン：タンバのツボツボ
	case POKE_MEET_HIKYAKU:		///< イベントポケモン：ひきゃく
		MSGMAN_GetString( wk->mman, str_dendemo_meet8, wk->tmpbuf1 );
		WORDSET_RegisterPlaceName( wk->wset, 0, pd->birth );
		WORDSET_ExpandStr( wk->wset, wk->tmpbuf2, wk->tmpbuf1 );
		break;
	}
	GF_STR_PrintColor( &win[2], FONT_SYSTEM, wk->tmpbuf2, 2, 24, MSG_NO_PUT, FCOL_WN15, NULL );
	GF_BGL_BmpWinCgxOn( &win[2] );
}

//--------------------------------------------------------------------------------------------
/**
 * シーン１：ＯＢＪ初期化
 *
 * @param	wk		画面ワーク
 * @param	num		ポケモン位置
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ObjInit1st( DEMO_WORK * wk, u32 num )
{
	PokeObjAdd( wk, num );
	GF_Disp_GX_VisibleControl( GX_PLANEMASK_OBJ, VISIBLE_ON );
}

//--------------------------------------------------------------------------------------------
/**
 * シーン１：ＯＢＪ削除
 *
 * @param	wk		画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ObjExit1st( DEMO_WORK * wk )
{
	u32	i;

	for( i=0; i<OBJID_MAX; i++ ){
		ObjDel( wk, i );
	}

	PokeWalkResFree( wk );
	PokeGraResFree( wk );
}

//--------------------------------------------------------------------------------------------
/**
 * ポケモンＯＢＪ追加
 *
 * @param	wk		画面ワーク
 * @param	num		ポケモン位置
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void PokeObjAdd( DEMO_WORK * wk, u32 num )
{
	POKE_DATA * pd;
	u32	i;

	pd = &wk->poke[num];

	PokeGraResLoad( wk );
	PokeWalkResLoad( wk, pd );

	for( i=0; i<=OBJID_1ST_POKE_WALK_S; i++ ){
		wk->cap[i] = CATS_ObjectAdd_S( wk->csp, wk->crp, &Cla1stScenePrm[i] );
	}

	PokeGraChange( wk, pd, PARA_FRONT, OBJID_1ST_POKE );
	PokeGraChange( wk, pd, PARA_BACK, OBJID_1ST_POKE_BACK );
	PokeWalkChange( wk, pd, OBJID_1ST_POKE_WALK );
	if( pd->mons == MONSNO_KURABU || pd->mons == MONSNO_KINGURAA ){
		ObjAnmSet( wk, OBJID_1ST_POKE_WALK, 2 );
		ObjAnmSet( wk, OBJID_1ST_POKE_WALK_S, 2 );
	}

	PokeShadowColSet( wk, OBJID_1ST_POKE_S, SHADOW_COL_BLACK );
	PokeShadowColSet( wk, OBJID_1ST_POKE_BACK_S, SHADOW_COL_BLACK );
	PokeShadowColSet( wk, OBJID_1ST_POKE_WALK_S, SHADOW_COL_BLACK );
}

//--------------------------------------------------------------------------------------------
/**
 * 連れ歩きポケモン座標調整
 *
 * @param	wk		画面ワーク
 * @param	pd		ポケモンデータ
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void PokeWalkPosMove( DEMO_WORK * wk, POKE_DATA * pd )
{
	// 連れ歩きポケモンの位置補正
	if( pd->info.BigSize ){
		CATS_ObjectPosMoveCap( wk->cap[OBJID_1ST_POKE_WALK], -32, -32 );
		CATS_ObjectPosMoveCap( wk->cap[OBJID_1ST_POKE_WALK_S], -32, -32 );
	}else{
		CATS_ObjectPosMoveCap( wk->cap[OBJID_1ST_POKE_WALK], -16, -16 );
		CATS_ObjectPosMoveCap( wk->cap[OBJID_1ST_POKE_WALK_S], -16, -16 );
	}
}

//--------------------------------------------------------------------------------------------
/**
 * シーン１：動作初期化
 *
 * @param	wk		画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void Scene01_MoveInit( DEMO_WORK * wk )
{
	POKE_DATA * pd;
	s16	x, y;

	pd = &wk->poke[wk->mv_poke];

	ObjInit1st( wk, wk->mv_poke );			// ＯＢＪ初期化

	// 文字面
	GF_BGL_ScrClear( wk->bgl, GF_BGL_FRAME0_M );	// 文字面クリア
	GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME0_M, GF_BGL_SCROLL_X_SET, 0 );
	GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME0_M, GF_BGL_SCROLL_Y_SET, 0 );

	if( ( wk->mv_poke & 1 ) == 0 ){
		// 固定幕面
		GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME1_M, GF_BGL_SCROLL_X_SET, 0 );
		GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME1_M, GF_BGL_SCROLL_Y_SET, 0 );
		// 動作幕面
		GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME2_M, GF_BGL_SCROLL_X_SET, 0 );
		GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME2_M, GF_BGL_SCROLL_Y_SET, 0 );
		// 背景
		GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME3_M, GF_BGL_SCROLL_X_SET, 0 );
		GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME3_M, GF_BGL_SCROLL_Y_SET, 0 );

		// 正面ポケモン
		CATS_ObjectPosSetCap( wk->cap[OBJID_1ST_POKE], S1_F_POKE_INIT_X_L, S1_F_POKE_INIT_Y_L );
		CATS_ObjectPosSetCap( wk->cap[OBJID_1ST_POKE_S], S1_FS_POKE_INIT_X_L, S1_FS_POKE_INIT_Y_L );
		// 背面ポケモン
		CATS_ObjectPosSetCap( wk->cap[OBJID_1ST_POKE_BACK], S1_B_POKE_INIT_X_L, S1_B_POKE_Y+pd->height );
		CATS_ObjectPosSetCap( wk->cap[OBJID_1ST_POKE_BACK_S], S1_BS_POKE_INIT_X_L, S1_B_POKE_Y+pd->height );
		// 連れ歩きポケモン
		CATS_ObjectPosSetCap( wk->cap[OBJID_1ST_POKE_WALK], S1_C3_W_POKE_INIT_X_L, S1_C3_W_POKE_INIT_Y_L );
		CATS_ObjectPosSetCap( wk->cap[OBJID_1ST_POKE_WALK_S], S1_C3_WS_POKE_INIT_X_L, S1_C3_WS_POKE_INIT_Y_L );

		// BMP
		Scene01PokeDataSet( wk, wk->mv_poke, S1_BMPWIN_NAME_L );
	}else{
		// 固定幕面
		GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME1_M, GF_BGL_SCROLL_X_SET, 0 );
		GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME1_M, GF_BGL_SCROLL_Y_SET, 256 );
		// 動作幕面
		GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME2_M, GF_BGL_SCROLL_X_SET, -184 );
		GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME2_M, GF_BGL_SCROLL_Y_SET, 0 );
		// 背景
		GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME3_M, GF_BGL_SCROLL_X_SET, 256 );
		GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME3_M, GF_BGL_SCROLL_Y_SET, 0 );

		// 正面ポケモン
		CATS_ObjectPosSetCap( wk->cap[OBJID_1ST_POKE], S1_F_POKE_INIT_X_R, S1_F_POKE_INIT_Y_R );
		CATS_ObjectPosSetCap( wk->cap[OBJID_1ST_POKE_S], S1_FS_POKE_INIT_X_R, S1_FS_POKE_INIT_Y_R );
		// 背面ポケモン
		CATS_ObjectPosSetCap( wk->cap[OBJID_1ST_POKE_BACK], S1_B_POKE_INIT_X_R, S1_B_POKE_Y+pd->height );
		CATS_ObjectPosSetCap( wk->cap[OBJID_1ST_POKE_BACK_S], S1_BS_POKE_INIT_X_R, S1_B_POKE_Y+pd->height );
		// 連れ歩きポケモン
		CATS_ObjectPosSetCap( wk->cap[OBJID_1ST_POKE_WALK], S1_C3_W_POKE_INIT_X_R, S1_C3_W_POKE_INIT_Y_R );
		CATS_ObjectPosSetCap( wk->cap[OBJID_1ST_POKE_WALK_S], S1_C3_WS_POKE_INIT_X_R, S1_C3_WS_POKE_INIT_Y_R );

		// BMP
		Scene01PokeDataSet( wk, wk->mv_poke, S1_BMPWIN_NAME_R );
	}

	CATS_ObjectAffineSetCap( wk->cap[OBJID_1ST_POKE], CLACT_AFFINE_DOUBLE );
	CATS_ObjectAffineSetCap( wk->cap[OBJID_1ST_POKE_S], CLACT_AFFINE_DOUBLE );
	CATS_ObjectScaleSetCap( wk->cap[OBJID_1ST_POKE_S], 1.5, 1.5 );

	PokeWalkPosMove( wk, pd );

	GF_BGL_LoadScreenV_Req( wk->bgl, GF_BGL_FRAME0_M );
}

//--------------------------------------------------------------------------------------------
/**
 * シーン１：動作メイン処理（左開き）
 *
 * @param	wk		画面ワーク
 *
 * @retval	"1 = 処理中"
 * @retval	"0 = それ以外"
 */
//--------------------------------------------------------------------------------------------
static int VFunc1stSceneLeft( DEMO_WORK * wk )
{
	switch( wk->vseq ){
	case 0:		// 幕開き＆背面移動
		if( wk->vcnt == S1_CASE0_FRAME ){
			u8	height = wk->poke[wk->mv_poke].height;
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME1_M, GF_BGL_SCROLL_X_SET, S1_BG1_SCROLL_END_L );
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME2_M, GF_BGL_SCROLL_X_SET, S1_BG2_SCROLL_END_L );
			CATS_ObjectPosSetCap( wk->cap[OBJID_1ST_POKE_BACK], S1_B_POKE_END_X_L, S1_B_POKE_Y+height );
			CATS_ObjectPosSetCap( wk->cap[OBJID_1ST_POKE_BACK_S], S1_BS_POKE_END_X_L, S1_B_POKE_Y+height );
			wk->vcnt = 0;
			wk->vseq++;
		}else{
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME1_M, GF_BGL_SCROLL_X_DEC, S1_WIPE_BG_SCROLL_SPD );
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME2_M, GF_BGL_SCROLL_X_INC, S1_WIPE_BG_SCROLL_SPD );
			CATS_ObjectPosMoveCap( wk->cap[OBJID_1ST_POKE_BACK], -S1_B_POKE_MV_SPD, 0 );
			CATS_ObjectPosMoveCap( wk->cap[OBJID_1ST_POKE_BACK_S], -S1_BS_POKE_MV_SPD, 0 );
			wk->vcnt++;
		}
		break;

	case 1:		// ウェイト＆背面アニメ＆鳴き声
		wk->b_anm_flg = 1;
		wk->vseq++;
		break;

	case 2:		// アニメウェイト＆通常ウェイト
		if( wk->vcnt == S1_CASE2_FRAME ){
			wk->vcnt = 0;
			wk->vseq++;
		}else{
			wk->vcnt++;
		}
		break;

	case 3:		// 連れ歩き移動
		if( wk->vcnt == S1_CASE3_FRAME ){
			CATS_ObjectPosSetCap( wk->cap[OBJID_1ST_POKE_WALK], S1_C3_W_POKE_END_X_L, S1_C3_W_POKE_END_Y_L );
			CATS_ObjectPosSetCap( wk->cap[OBJID_1ST_POKE_WALK_S], S1_C3_WS_POKE_END_X_L, S1_C3_WS_POKE_END_Y_L );
			PokeWalkPosMove( wk, &wk->poke[wk->mv_poke] );
			wk->vcnt = 0;
			wk->vseq++;
		}else{
			CATS_ObjectPosMoveCap( wk->cap[OBJID_1ST_POKE_WALK], S1_C3_W_POKE_SPD_X, S1_C3_W_POKE_SPD_Y );
			CATS_ObjectPosMoveCap( wk->cap[OBJID_1ST_POKE_WALK_S], S1_C3_WS_POKE_SPD_X, S1_C3_WS_POKE_SPD_Y );
			wk->vcnt++;
		}
		break;

	case 4:		// 連れ歩きアニメ
		if( wk->poke[wk->mv_poke].mons == MONSNO_KURABU ||
			wk->poke[wk->mv_poke].mons == MONSNO_KINGURAA ){
			ObjAnmSet( wk, OBJID_1ST_POKE_WALK, 3 );
			ObjAnmSet( wk, OBJID_1ST_POKE_WALK_S, 3 );
		}else{
			ObjAnmSet( wk, OBJID_1ST_POKE_WALK, 1 );
			ObjAnmSet( wk, OBJID_1ST_POKE_WALK_S, 1 );
		}
		wk->vseq++;
		break;

	case 5:		// アニメウェイト＆通常ウェイト
		if( wk->vcnt == S1_CASE5_FRAME ){
			wk->vcnt = 0;
			wk->vseq++;
		}else{
			wk->vcnt++;
		}
		break;

	case 6:		//「でんどういり〜」表示
		GF_BGL_BmpWinOnVReq( &wk->win[S1_BMPWIN_TITLE] );
		wk->vseq++;
		break;

	case 7:		// ウェイト
		if( wk->vcnt == S1_CASE7_FRAME ){
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME2_M, GF_BGL_SCROLL_X_SET, S1_C8_BG2_SCROLL_INIT_X_L );
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME2_M, GF_BGL_SCROLL_Y_SET, S1_C8_BG2_SCROLL_INIT_Y_L );
			CATS_ObjectBGPriSetCap( wk->cap[OBJID_1ST_POKE_BACK], 2 );
			CATS_ObjectBGPriSetCap( wk->cap[OBJID_1ST_POKE_BACK_S], 2 );
			wk->vcnt = 0;
			wk->vseq++;
		}else{
			wk->vcnt++;
		}
		break;

	case 8:		// 正面移動
		if( wk->vcnt == S1_CASE8_FRAME ){
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME2_M, GF_BGL_SCROLL_X_SET, S1_C8_BG2_SCROLL_END_X_L );
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME2_M, GF_BGL_SCROLL_Y_SET, S1_C8_BG2_SCROLL_END_Y_L );
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME3_M, GF_BGL_SCROLL_Y_SET, 256 );
			CATS_ObjectPosSetCap( wk->cap[OBJID_1ST_POKE], S1_F_POKE_END_X_L, S1_F_POKE_END_Y_L );
			CATS_ObjectPosSetCap( wk->cap[OBJID_1ST_POKE_S], S1_FS_POKE_END_X_L, S1_FS_POKE_END_Y_L );
			wk->vcnt = 0;
			wk->vseq++;
		}else{
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME2_M, GF_BGL_SCROLL_X_INC, S1_C8_BG2_SCROLL_MV_X );
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME2_M, GF_BGL_SCROLL_Y_DEC, S1_C8_BG2_SCROLL_MV_Y );
			CATS_ObjectPosMoveCap( wk->cap[OBJID_1ST_POKE], -S1_F_POKE_MV_X_SPD, S1_F_POKE_MV_Y_SPD );
			CATS_ObjectPosMoveCap( wk->cap[OBJID_1ST_POKE_S], -S1_FS_POKE_MV_X_SPD, S1_FS_POKE_MV_Y_SPD );
			wk->vcnt++;
		}
		break;

	case 9:		// ニックネーム表示＆ＢＧパレット変更＆各ＯＢＪのパレット変更
		GF_BGL_BmpWinOnVReq( &wk->win[S1_BMPWIN_NAME_L] );
		PokeShadowColSet( wk, OBJID_1ST_POKE_BACK, SHADOW_COL_BLACK );
		PokeShadowColSet( wk, OBJID_1ST_POKE_WALK, SHADOW_COL_BLACK );
		PokeShadowColSet( wk, OBJID_1ST_POKE_BACK_S, SHADOW_COL_RED );
		PokeShadowColSet( wk, OBJID_1ST_POKE_WALK_S, SHADOW_COL_RED );
		wk->vseq++;
		break;

	case 10:		// ウェイト
		if( wk->vcnt == S1_CASE10_FRAME ){
			wk->vcnt = 0;
			wk->vseq++;
		}else{
			wk->vcnt++;
		}
		break;

	case 11:		// 正面アニメ＆種族・レベル表示
		GF_BGL_BmpWinOnVReq( &wk->win[S1_BMPWIN_PARAM_L] );
		wk->f_anm_flg = 1;
		wk->vseq++;
		break;

	case 12:		// 正面アニメ＆ウェイト
		if( wk->vcnt == S1_CASE12_FRAME ){
			wk->vcnt = 0;
			wk->vseq++;
		}else{
			wk->vcnt++;
		}
		break;

	case 13:		// 親名・捕獲場所表示
		GF_BGL_BmpWinOnVReq( &wk->win[S1_BMPWIN_MEMO_L] );
		wk->vseq++;
		break;

	case 14:		// ウェイト
		if( wk->vcnt == S1_CASE14_FRAME ){
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME2_M, GF_BGL_SCROLL_X_SET, S1_BG2_SCROLL_END_L );
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME2_M, GF_BGL_SCROLL_Y_SET, 0 );
			CATS_ObjectBGPriSetCap( wk->cap[OBJID_1ST_POKE], 3 );
			CATS_ObjectBGPriSetCap( wk->cap[OBJID_1ST_POKE_S], 3 );
			CATS_ObjectBGPriSetCap( wk->cap[OBJID_1ST_POKE_BACK], 3 );
			CATS_ObjectBGPriSetCap( wk->cap[OBJID_1ST_POKE_BACK_S], 3 );
			CATS_ObjectBGPriSetCap( wk->cap[OBJID_1ST_POKE_WALK], 3 );
			CATS_ObjectBGPriSetCap( wk->cap[OBJID_1ST_POKE_WALK_S], 3 );
			wk->sc_poke = 1.0;
			wk->sc_shadow = 1.5;
			wk->vcnt = 0;
			wk->vseq++;
		}else{
			wk->vcnt++;
		}
		break;

	case 15:		// 終了動作
		if( wk->vcnt == S1_CASE15_FRAME ){
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME0_M, GF_BGL_SCROLL_X_SET, S1_C15_BG0_SCROLL_END_X_L );
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME0_M, GF_BGL_SCROLL_Y_SET, S1_C15_BG0_SCROLL_END_Y_L );
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME1_M, GF_BGL_SCROLL_X_SET, S1_BG1_SCROLL_INIT_L );
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME2_M, GF_BGL_SCROLL_X_SET, S1_BG2_SCROLL_INIT_L );
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME3_M, GF_BGL_SCROLL_X_SET, S1_C15_BG3_SCROLL_END_X_L );
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME3_M, GF_BGL_SCROLL_Y_SET, S1_C15_BG3_SCROLL_END_Y_L );
			CATS_ObjectPosSetCap( wk->cap[OBJID_1ST_POKE_BACK], S1_C15_B_POKE_END_X_L, S1_C15_B_POKE_END_Y_L );
			CATS_ObjectPosSetCap( wk->cap[OBJID_1ST_POKE_BACK_S], S1_C15_BS_POKE_END_X_L, S1_C15_BS_POKE_END_Y_L );
			CATS_ObjectPosSetCap( wk->cap[OBJID_1ST_POKE_WALK], S1_C15_W_POKE_END_X_L, S1_C15_W_POKE_END_Y_L );
			CATS_ObjectPosSetCap( wk->cap[OBJID_1ST_POKE_WALK_S], S1_C15_WS_POKE_END_X_L, S1_C15_WS_POKE_END_Y_L );
			CATS_ObjectPosSetCap( wk->cap[OBJID_1ST_POKE], S1_C15_F_POKE_END_X_L, S1_C15_F_POKE_END_Y_L );
			CATS_ObjectPosSetCap( wk->cap[OBJID_1ST_POKE_S], S1_C15_FS_POKE_END_X_L, S1_C15_FS_POKE_END_Y_L );
			CATS_ObjectScaleSetCap( wk->cap[OBJID_1ST_POKE], 1.8, 1.8 );
			CATS_ObjectScaleSetCap( wk->cap[OBJID_1ST_POKE_S], 2.0, 2.0 );
			wk->vcnt = 0;
			wk->vseq++;
		}else{
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME0_M, GF_BGL_SCROLL_X_DEC, S1_C15_BG0_SCROLL_MV_X );
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME0_M, GF_BGL_SCROLL_Y_INC, S1_C15_BG0_SCROLL_MV_Y );
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME1_M, GF_BGL_SCROLL_X_INC, S1_WIPE_BG_SCROLL_SPD );
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME2_M, GF_BGL_SCROLL_X_DEC, S1_WIPE_BG_SCROLL_SPD );
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME3_M, GF_BGL_SCROLL_X_INC, S1_C15_BG3_SCROLL_MV_X );
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME3_M, GF_BGL_SCROLL_Y_DEC, S1_C15_BG3_SCROLL_MV_Y );
			CATS_ObjectPosMoveCap( wk->cap[OBJID_1ST_POKE_BACK], S1_C15_B_POKE_MV_SPD_X, S1_C15_B_POKE_MV_SPD_Y );
			CATS_ObjectPosMoveCap( wk->cap[OBJID_1ST_POKE_BACK_S], S1_C15_BS_POKE_MV_SPD_X, S1_C15_BS_POKE_MV_SPD_Y );
			CATS_ObjectPosMoveCap( wk->cap[OBJID_1ST_POKE_WALK], -S1_C15_W_POKE_MV_SPD_X, -S1_C15_W_POKE_MV_SPD_Y );
			CATS_ObjectPosMoveCap( wk->cap[OBJID_1ST_POKE_WALK_S], -S1_C15_WS_POKE_MV_SPD_X, -S1_C15_WS_POKE_MV_SPD_Y );
			CATS_ObjectPosMoveCap( wk->cap[OBJID_1ST_POKE], -S1_C15_F_POKE_MV_SPD_X, S1_C15_F_POKE_MV_SPD_Y );
			CATS_ObjectPosMoveCap( wk->cap[OBJID_1ST_POKE_S], -S1_C15_FS_POKE_MV_SPD_X, S1_C15_FS_POKE_MV_SPD_Y );
			wk->sc_poke += 0.08;
			wk->sc_shadow += 0.05;
			CATS_ObjectScaleSetCap( wk->cap[OBJID_1ST_POKE], wk->sc_poke, wk->sc_poke );
			CATS_ObjectScaleSetCap( wk->cap[OBJID_1ST_POKE_S], wk->sc_shadow, wk->sc_shadow );
			wk->vcnt++;
		}
		break;

	case 16:
		if( wk->vcnt == S1_CASE16_FRAME ){
			return 0;
		}
		wk->vcnt++;
	}

	return 1;
}

//--------------------------------------------------------------------------------------------
/**
 * シーン１：動作メイン処理（右開き）
 *
 * @param	wk		画面ワーク
 *
 * @retval	"1 = 処理中"
 * @retval	"0 = それ以外"
 */
//--------------------------------------------------------------------------------------------
static int VFunc1stSceneRight( DEMO_WORK * wk )
{
	switch( wk->vseq ){
	case 0:		// 幕開き＆背面移動
		if( wk->vcnt == S1_CASE0_FRAME ){
			u8	height = wk->poke[wk->mv_poke].height;
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME1_M, GF_BGL_SCROLL_X_SET, S1_BG1_SCROLL_END_R );
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME2_M, GF_BGL_SCROLL_X_SET, S1_BG2_SCROLL_END_R );
			CATS_ObjectPosSetCap( wk->cap[OBJID_1ST_POKE_BACK], S1_B_POKE_END_X_R, S1_B_POKE_Y+height );
			CATS_ObjectPosSetCap( wk->cap[OBJID_1ST_POKE_BACK_S], S1_BS_POKE_END_X_R, S1_B_POKE_Y+height );
			wk->vcnt = 0;
			wk->vseq++;
		}else{
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME1_M, GF_BGL_SCROLL_X_INC, S1_WIPE_BG_SCROLL_SPD );
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME2_M, GF_BGL_SCROLL_X_DEC, S1_WIPE_BG_SCROLL_SPD );
			CATS_ObjectPosMoveCap( wk->cap[OBJID_1ST_POKE_BACK], S1_B_POKE_MV_SPD, 0 );
			CATS_ObjectPosMoveCap( wk->cap[OBJID_1ST_POKE_BACK_S], S1_BS_POKE_MV_SPD, 0 );
			wk->vcnt++;
		}
		break;

	case 1:		// ウェイト＆背面アニメ＆鳴き声
		wk->b_anm_flg = 1;
		wk->vseq++;
		break;

	case 2:		// アニメウェイト＆通常ウェイト
		if( wk->vcnt == S1_CASE2_FRAME ){
			wk->vcnt = 0;
			wk->vseq++;
		}else{
			wk->vcnt++;
		}
		break;

	case 3:		// 連れ歩き移動
		if( wk->vcnt == S1_CASE3_FRAME ){
			CATS_ObjectPosSetCap( wk->cap[OBJID_1ST_POKE_WALK], S1_C3_W_POKE_END_X_R, S1_C3_W_POKE_END_Y_R );
			CATS_ObjectPosSetCap( wk->cap[OBJID_1ST_POKE_WALK_S], S1_C3_WS_POKE_END_X_R, S1_C3_WS_POKE_END_Y_R );
			PokeWalkPosMove( wk, &wk->poke[wk->mv_poke] );
			wk->vcnt = 0;
			wk->vseq++;
		}else{
			CATS_ObjectPosMoveCap( wk->cap[OBJID_1ST_POKE_WALK], -S1_C3_W_POKE_SPD_X, S1_C3_W_POKE_SPD_Y );
			CATS_ObjectPosMoveCap( wk->cap[OBJID_1ST_POKE_WALK_S], -S1_C3_WS_POKE_SPD_X, S1_C3_WS_POKE_SPD_Y );
			wk->vcnt++;
		}
		break;

	case 4:		// 連れ歩きアニメ
		if( wk->poke[wk->mv_poke].mons == MONSNO_KURABU ||
			wk->poke[wk->mv_poke].mons == MONSNO_KINGURAA ){
			ObjAnmSet( wk, OBJID_1ST_POKE_WALK, 3 );
			ObjAnmSet( wk, OBJID_1ST_POKE_WALK_S, 3 );
		}else{
			ObjAnmSet( wk, OBJID_1ST_POKE_WALK, 1 );
			ObjAnmSet( wk, OBJID_1ST_POKE_WALK_S, 1 );
		}
		wk->vseq++;
		break;

	case 5:		// アニメウェイト＆通常ウェイト
		if( wk->vcnt == S1_CASE5_FRAME ){
			wk->vcnt = 0;
			wk->vseq++;
		}else{
			wk->vcnt++;
		}
		break;

	case 6:		//「でんどういり〜」表示
		GF_BGL_BmpWinOnVReq( &wk->win[S1_BMPWIN_TITLE] );
		wk->vseq++;
		break;

	case 7:		// ウェイト
		if( wk->vcnt == S1_CASE7_FRAME ){
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME2_M, GF_BGL_SCROLL_X_SET, S1_C8_BG2_SCROLL_INIT_X_R );
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME2_M, GF_BGL_SCROLL_Y_SET, S1_C8_BG2_SCROLL_INIT_Y_R );
			CATS_ObjectBGPriSetCap( wk->cap[OBJID_1ST_POKE_BACK], 2 );
			CATS_ObjectBGPriSetCap( wk->cap[OBJID_1ST_POKE_BACK_S], 2 );
			wk->vcnt = 0;
			wk->vseq++;
		}else{
			wk->vcnt++;
		}
		break;

	case 8:		// 正面移動
		if( wk->vcnt == S1_CASE8_FRAME ){
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME2_M, GF_BGL_SCROLL_X_SET, S1_C8_BG2_SCROLL_END_X_R );
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME2_M, GF_BGL_SCROLL_Y_SET, S1_C8_BG2_SCROLL_END_Y_R );
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME3_M, GF_BGL_SCROLL_Y_SET, 256 );
			CATS_ObjectPosSetCap( wk->cap[OBJID_1ST_POKE], S1_F_POKE_END_X_R, S1_F_POKE_END_Y_R );
			CATS_ObjectPosSetCap( wk->cap[OBJID_1ST_POKE_S], S1_FS_POKE_END_X_R, S1_FS_POKE_END_Y_R );
			wk->vcnt = 0;
			wk->vseq++;
		}else{
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME2_M, GF_BGL_SCROLL_X_DEC, S1_C8_BG2_SCROLL_MV_X );
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME2_M, GF_BGL_SCROLL_Y_DEC, S1_C8_BG2_SCROLL_MV_Y );
			CATS_ObjectPosMoveCap( wk->cap[OBJID_1ST_POKE], S1_F_POKE_MV_X_SPD, S1_F_POKE_MV_Y_SPD );
			CATS_ObjectPosMoveCap( wk->cap[OBJID_1ST_POKE_S], S1_FS_POKE_MV_X_SPD, S1_FS_POKE_MV_Y_SPD );
			wk->vcnt++;
		}
		break;

	case 9:		// ニックネーム表示＆ＢＧパレット変更＆各ＯＢＪのパレット変更
		GF_BGL_BmpWinOnVReq( &wk->win[S1_BMPWIN_NAME_R] );
		PokeShadowColSet( wk, OBJID_1ST_POKE_BACK, SHADOW_COL_BLACK );
		PokeShadowColSet( wk, OBJID_1ST_POKE_WALK, SHADOW_COL_BLACK );
		PokeShadowColSet( wk, OBJID_1ST_POKE_BACK_S, SHADOW_COL_RED );
		PokeShadowColSet( wk, OBJID_1ST_POKE_WALK_S, SHADOW_COL_RED );
		wk->vseq++;
		break;

	case 10:		// ウェイト
		if( wk->vcnt == S1_CASE10_FRAME ){
			wk->vcnt = 0;
			wk->vseq++;
		}else{
			wk->vcnt++;
		}
		break;

	case 11:		// 正面アニメ＆種族・レベル表示
		GF_BGL_BmpWinOnVReq( &wk->win[S1_BMPWIN_PARAM_R] );
		wk->f_anm_flg = 1;
		wk->vseq++;
		break;

	case 12:		// 正面アニメ＆ウェイト
		if( wk->vcnt == S1_CASE12_FRAME ){
			wk->vcnt = 0;
			wk->vseq++;
		}else{
			wk->vcnt++;
		}
		break;

	case 13:		// 親名・捕獲場所表示
		GF_BGL_BmpWinOnVReq( &wk->win[S1_BMPWIN_MEMO_R] );
		wk->vseq++;
		break;

	case 14:		// ウェイト
		if( wk->vcnt == S1_CASE14_FRAME ){
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME2_M, GF_BGL_SCROLL_X_SET, S1_BG2_SCROLL_END_R );
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME2_M, GF_BGL_SCROLL_Y_SET, 0 );
			CATS_ObjectBGPriSetCap( wk->cap[OBJID_1ST_POKE], 3 );
			CATS_ObjectBGPriSetCap( wk->cap[OBJID_1ST_POKE_S], 3 );
			CATS_ObjectBGPriSetCap( wk->cap[OBJID_1ST_POKE_BACK], 3 );
			CATS_ObjectBGPriSetCap( wk->cap[OBJID_1ST_POKE_BACK_S], 3 );
			CATS_ObjectBGPriSetCap( wk->cap[OBJID_1ST_POKE_WALK], 3 );
			CATS_ObjectBGPriSetCap( wk->cap[OBJID_1ST_POKE_WALK_S], 3 );
			wk->sc_poke = 1.0;
			wk->sc_shadow = 1.5;
			wk->vcnt = 0;
			wk->vseq++;
		}else{
			wk->vcnt++;
		}
		break;

	case 15:
		if( wk->vcnt == S1_CASE15_FRAME ){
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME0_M, GF_BGL_SCROLL_X_SET, S1_C15_BG0_SCROLL_END_X_R );
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME0_M, GF_BGL_SCROLL_Y_SET, S1_C15_BG0_SCROLL_END_Y_R );
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME1_M, GF_BGL_SCROLL_X_SET, S1_BG1_SCROLL_INIT_R );
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME2_M, GF_BGL_SCROLL_X_SET, S1_BG2_SCROLL_INIT_R );
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME3_M, GF_BGL_SCROLL_X_SET, S1_C15_BG3_SCROLL_END_X_R );
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME3_M, GF_BGL_SCROLL_Y_SET, S1_C15_BG3_SCROLL_END_Y_R );
			CATS_ObjectPosSetCap( wk->cap[OBJID_1ST_POKE_BACK], S1_C15_B_POKE_END_X_R, S1_C15_B_POKE_END_Y_R );
			CATS_ObjectPosSetCap( wk->cap[OBJID_1ST_POKE_BACK_S], S1_C15_BS_POKE_END_X_R, S1_C15_BS_POKE_END_Y_R );
			CATS_ObjectPosSetCap( wk->cap[OBJID_1ST_POKE_WALK], S1_C15_W_POKE_END_X_R, S1_C15_W_POKE_END_Y_R );
			CATS_ObjectPosSetCap( wk->cap[OBJID_1ST_POKE_WALK_S], S1_C15_WS_POKE_END_X_R, S1_C15_WS_POKE_END_Y_R );
			CATS_ObjectPosSetCap( wk->cap[OBJID_1ST_POKE], S1_C15_F_POKE_END_X_R, S1_C15_F_POKE_END_Y_R );
			CATS_ObjectPosSetCap( wk->cap[OBJID_1ST_POKE_S], S1_C15_FS_POKE_END_X_R, S1_C15_FS_POKE_END_Y_R );
			CATS_ObjectScaleSetCap( wk->cap[OBJID_1ST_POKE], 1.8, 1.8 );
			CATS_ObjectScaleSetCap( wk->cap[OBJID_1ST_POKE_S], 2.0, 2.0 );
			wk->vcnt = 0;
			wk->vseq++;
		}else{
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME0_M, GF_BGL_SCROLL_X_INC, S1_C15_BG0_SCROLL_MV_X );
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME0_M, GF_BGL_SCROLL_Y_INC, S1_C15_BG0_SCROLL_MV_Y );
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME1_M, GF_BGL_SCROLL_X_DEC, S1_WIPE_BG_SCROLL_SPD );
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME2_M, GF_BGL_SCROLL_X_INC, S1_WIPE_BG_SCROLL_SPD );
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME3_M, GF_BGL_SCROLL_X_DEC, S1_C15_BG3_SCROLL_MV_X );
			GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME3_M, GF_BGL_SCROLL_Y_DEC, S1_C15_BG3_SCROLL_MV_Y );
			CATS_ObjectPosMoveCap( wk->cap[OBJID_1ST_POKE_BACK], -S1_C15_B_POKE_MV_SPD_X, S1_C15_B_POKE_MV_SPD_Y );
			CATS_ObjectPosMoveCap( wk->cap[OBJID_1ST_POKE_BACK_S], -S1_C15_BS_POKE_MV_SPD_X, S1_C15_BS_POKE_MV_SPD_Y );
			CATS_ObjectPosMoveCap( wk->cap[OBJID_1ST_POKE_WALK], S1_C15_W_POKE_MV_SPD_X, -S1_C15_W_POKE_MV_SPD_Y );
			CATS_ObjectPosMoveCap( wk->cap[OBJID_1ST_POKE_WALK_S], S1_C15_WS_POKE_MV_SPD_X, -S1_C15_WS_POKE_MV_SPD_Y );
			CATS_ObjectPosMoveCap( wk->cap[OBJID_1ST_POKE], S1_C15_F_POKE_MV_SPD_X, S1_C15_F_POKE_MV_SPD_Y );
			CATS_ObjectPosMoveCap( wk->cap[OBJID_1ST_POKE_S], S1_C15_FS_POKE_MV_SPD_X, S1_C15_FS_POKE_MV_SPD_Y );
			wk->sc_poke += 0.08;
			wk->sc_shadow += 0.05;
			CATS_ObjectScaleSetCap( wk->cap[OBJID_1ST_POKE], wk->sc_poke, wk->sc_poke );
			CATS_ObjectScaleSetCap( wk->cap[OBJID_1ST_POKE_S], wk->sc_shadow, wk->sc_shadow );
			wk->vcnt++;
		}
		break;

	case 16:
		if( wk->vcnt ==S1_CASE16_FRAME ){
			return 0;
		}
		wk->vcnt++;
	}

	return 1;
}

//--------------------------------------------------------------------------------------------
/**
 * ポケモンデータ作成
 *
 * @param	wk		画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void PokeDataMake( DEMO_WORK * wk )
{
	POKEMON_PARAM * pp;
	ARCHANDLE * anm_ah;
	SOFT_SPRITE_ARC  ssa;
	BOOL fastFlag;
	u32	i;
	CHANGES_INTO_DATA_RECT rect[] =
	{
		{ POKE_TEX_X, POKE_TEX_Y, POKE_TEX_W, POKE_TEX_H },
		{ POKE_TEX_X+POKE_TEX_W, POKE_TEX_Y, POKE_TEX_W, POKE_TEX_H },
	};

	anm_ah = ArchiveDataHandleOpen( ARC_PM_EDIT, HEAPID_DENDOU_DEMO );

	for( i=0; i<PokeParty_GetPokeCount(wk->prm->party); i++ ){
		pp = PokeParty_GetMemberPointer( wk->prm->party, i );
		fastFlag = PokeParaFastModeOn( pp );
		if( PokeParaGet( pp, ID_PARA_tamago_flag, NULL ) == FALSE ){
			POKE_DATA * pd = &wk->poke[ wk->pokeCount ];
			pd->pp     = pp;
			pd->mons   = PokeParaGet( pp, ID_PARA_monsno, NULL);
			pd->rnd    = PokeParaGet( pp, ID_PARA_personal_rnd, NULL );
			pd->frm    = PokeParaGet( pp, ID_PARA_form_no, NULL);
			pd->sex    = PokeParaGet( pp, ID_PARA_sex, NULL );
#if	GS_BTS5568_20090716_FIX
			pd->height = PokeHeightGet( pd->mons, pd->sex, PARA_BACK, pd->frm, pd->rnd ) + 8;
#else
			pd->height = PokeHeightGet( pd->mons, pd->sex, PARA_BACK, pd->frm, pd->rnd );
#endif	// GS_BTS5568_20090716_FIX
			pd->birth  = PokeParaGet( pp, ID_PARA_birth_place, NULL );
			pd->lv     = PokeParaGet( pp, ID_PARA_level, NULL );
			pd->index  = i;
			// ニックネームに関係なく、ニドランの場合は性別を表示しない
			if( pd->mons == MONSNO_NIDORAN_F || pd->mons == MONSNO_NIDORAN_M ){
				pd->sex_put = 0;
			}else{
				pd->sex_put = 1;
			}
			ArchiveDataLoad( &pd->info, ARC_PAIR_POKE_INFO, PairPokeIdx_GetIdx(pd->mons) );

			// グラフィック読み込み
			// 正面
			PokeGraArcDataGetPP( &ssa, pp, PARA_FRONT );
			Ex_ChangesInto_OAM_from_PokeTex_RC(
				ssa.arc_no, ssa.index_chr, HEAPID_DENDOU_DEMO,
				&rect[0], &pd->cgxBuf[0][0], pd->rnd, TRUE, PARA_FRONT, pd->mons );
			Ex_ChangesInto_OAM_from_PokeTex_RC(
				ssa.arc_no, ssa.index_chr, HEAPID_DENDOU_DEMO,
				&rect[1], &pd->cgxBuf[0][POKEGRA_TEX_SIZE], pd->rnd, TRUE, PARA_FRONT, pd->mons );
			// 背面
			PokeGraArcDataGetPP( &ssa, pp, PARA_BACK );
			Ex_ChangesInto_OAM_from_PokeTex_RC(
				ssa.arc_no, ssa.index_chr, HEAPID_DENDOU_DEMO,
				&rect[0], &pd->cgxBuf[1][0], pd->rnd, TRUE, PARA_BACK, pd->mons );
			Ex_ChangesInto_OAM_from_PokeTex_RC(
				ssa.arc_no, ssa.index_chr, HEAPID_DENDOU_DEMO,
				&rect[1], &pd->cgxBuf[1][POKEGRA_TEX_SIZE], pd->rnd, TRUE, PARA_BACK, pd->mons );

			// アニメテーブル読み込み
			PokeEditData_AnimeSet( anm_ah, &pd->anim[0][0], pd->mons, CLIENT_TYPE_BB );
			PokeEditData_AnimeSet( anm_ah, &pd->anim[1][0], pd->mons, CLIENT_TYPE_AA );

			wk->pokeCount++;
		}
		PokeParaFastModeOff( pp, fastFlag );
	}

	ArchiveDataHandleClose( anm_ah );
}

//--------------------------------------------------------------------------------------------
/**
 * 出会い方パターンチェック
 *
 * @param	wk		画面ワーク
 * @param	pp		POKEMON_PARAM
 * @param	player	プレイヤーデータ
 *
 * @return	出会い方
 */
//--------------------------------------------------------------------------------------------
static POKE_MEET_PATTERN GetPokeMeetPattern( DEMO_WORK* wk, POKEMON_PARAM* pp, const MYSTATUS* player )
{
	BOOL fastFlag;
	POKE_MEET_PATTERN ptn = POKE_MEET_OTHER;

	fastFlag = PokeParaFastModeOn(pp);

	do {
		// ロムチェック
		{
			// AGBロムから来たケース
			int romVer = PokeParaGet( pp, ID_PARA_get_cassette, NULL );
			if( romVer == VERSION_SAPPHIRE || romVer == VERSION_RUBY || romVer == VERSION_EMERALD )
			{
				ptn = POKE_MEET_HOUEN;
				break;
			}
			if( romVer == VERSION_RED || romVer == VERSION_GREEN )
			{
				ptn = POKE_MEET_KANTOU;
				break;
			}
			if( romVer == VERSION_COLOSSEUM )
			{
				ptn = POKE_MEET_SOMEWHERE;
				break;
			}
			// D/P/PL
			if( romVer == VERSION_DIAMOND || romVer == VERSION_PEARL || romVer == VERSION_PLATINUM )
			{
				ptn = POKE_MEET_SHINOU;
				break;
			}
		}

		// 外部配布なら
		if( PokeParaGet( pp, ID_PARA_event_get_flag, NULL ) )
		{
			ptn = POKE_MEET_OTHER;
			break;
		}

		// イベントポケモン：タンバのツボツボ
		if( OnlyonePoke_KeepPokeCheck( pp, FLD_TRADE_TUBOTUBO ) == TRUE ){
			ptn = POKE_MEET_TSUBOTSUBO;
			break;
		}

		// イベントポケモン：ひきゃく
		if( OnlyonePoke_KeepPokeCheck( pp, FLD_TRADE_ONISUZUME ) == TRUE ){
			ptn = POKE_MEET_HIKYAKU;
			break;
		}

		// ID または 親名の不一致なら、通信交換とみなす
		{
			u32 playerID, pokeID;

			playerID = MyStatus_GetID( player );
			pokeID = PokeParaGet( pp, ID_PARA_id_no, NULL );

			if( playerID != pokeID )
			{
				ptn = POKE_MEET_TRADE;
				break;
			}

			MyStatus_CopyNameString( player, wk->tmpbuf1 );
			PokeParaGet( pp, ID_PARA_oyaname_buf, wk->tmpbuf2 );

			if( STRBUF_Compare( wk->tmpbuf1, wk->tmpbuf2 ) )
			{
				ptn = POKE_MEET_TRADE;
				break;
			}
		}

		// ここまで来たらタマゴ孵化か野生捕獲のはずだが、
		// 念のためヘンな場所コードが入っていたら「うんめいてきなであい」ということにしておく
		if( PokeParaGet( pp, ID_PARA_birth_place, NULL ) >= 2000 )
		{
			ptn = POKE_MEET_OTHER;
		}
		else
		{
			// ID_PARA_get_month は“タマゴをもらった日付（月）”という意味なので
			// これが０だったら野生で捕まえたものとみなす
			if( PokeParaGet( pp, ID_PARA_get_month, NULL ) == 0 )
			{
				ptn = POKE_MEET_CATCH;
			}
			else
			{
				ptn = POKE_MEET_BORN;
			}
		}


	}while(0);

	PokeParaFastModeOff(pp, fastFlag);

	return ptn;
}

//--------------------------------------------------------------------------------------------
/**
 * 連れ歩きポケモンのアーカイブインデックスを返す
 *
 * @param	inMonsNo	モンスターナンバー
 * @param	inFormNo	フォルムナンバー
 * @param	inSex		性別
 *
 * @return	アーカイブインデックス
 *
 *	pokethlon/poke_clact.cよりコピー
 */
//--------------------------------------------------------------------------------------------
static int GetMonsArcIdx(const int inMonsNo, const u16 inFormNo, const int inSex)
{
	int idx;
	if ( (inMonsNo<=0) || (MONSNO_END<inMonsNo) ){
		idx = 1;
	}else{
		idx = NARC_mmodel_tsure_001_nsbtx + PairPokeIdx_GetIdx(inMonsNo);
		//モンスターナンバーだけからだと不十分なので、ここからさらに調べる（フォルムとか）
		//性別による描き違いをして、かつ複数フォルムナンバー所持ポケモンはいないので、
		//性別違いをまずキーにして分岐
		if (PairPokeIdx_GetSexDif(inMonsNo)){		//性別による描き違いがある
			if(inSex == PARA_FEMALE ){ //メスの場合
				idx += 1;	//ベースから1シフトしたところがメスのコード
			}
		}else{		//性別による描き違いがない
			//フォルムを調べる
			int form;
			if ( inFormNo > PairPokeIdx_GetFormNum(inMonsNo) ){
				form = 0;
			}else{
				form = inFormNo;
			}
			idx += form;
		}
	}

	return idx;
}

// ポケモンアニメワーク
typedef struct {
	POKE_DATA * pd;
	SOFT_SPRITE_ANIME_WORK	ssawk;
	ARCHANDLE * pme_ah;
	u8 * cgx;
	u32	vram;
	u16	client_type;
	BOOL	voice;
}POKE_ANIM_WORK;

static void PokeAnimTask( TCB_PTR tcb, void * work );

//--------------------------------------------------------------------------------------------
/**
 * ポケモンアニメタスクセット
 *
 * @param	wk		画面ワーク
 * @param	pokeID	ポケモン位置
 * @param	objID	ＯＢＪ番号
 * @param	voice	鳴き声再生フラグ
 * @param	dir		向き（正面・背面）
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void PokeAnimTaskSet( DEMO_WORK * wk, int pokeID, int objID, BOOL voice, int dir )
{
	POKE_ANIM_WORK * awk;
	NNSG2dImageProxy * ipc;

	awk = sys_AllocMemory( HEAPID_DENDOU_DEMO, sizeof(POKE_ANIM_WORK) );

	awk->pd  = &wk->poke[pokeID];

	awk->voice  = voice;
	awk->pme_ah = wk->pme_ah;

	awk->vram = NNS_G2dGetImageLocation(
					CLACT_ImageProxyGet(wk->cap[objID]->act), NNS_G2D_VRAM_TYPE_2DMAIN );

	if( dir == PARA_FRONT ){
		awk->cgx  = &awk->pd->cgxBuf[0][0];
		awk->client_type = CLIENT_TYPE_BB;
		SoftSprite_SetupAnimeWork( &awk->ssawk, &awk->pd->anim[0][0] );
	}else{
		awk->cgx  = &awk->pd->cgxBuf[1][0];
		awk->client_type = CLIENT_TYPE_AA;
		SoftSprite_SetupAnimeWork( &awk->ssawk, &awk->pd->anim[1][0] );
	}

	TCB_Add( PokeAnimTask, awk, 0 );
}

//--------------------------------------------------------------------------------------------
/**
 * ポケモンアニメタスク
 *
 * @param	tcb			TCB
 * @param	work		画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void PokeAnimTask( TCB_PTR tcb, void * work )
{
	POKE_ANIM_WORK * wk = work;
	int	pat;

	if( wk->voice == TRUE ){
		u8	wait;
		PokeEditData_VoiceWaitSet( wk->pme_ah, &wait, wk->pd->mons, wk->client_type );
		if( wk->pd->mons == MONSNO_PERAPPU ){
			Snd_PerapVoiceWaitPlay( NULL, PM_MALE, PV_VOL_DEFAULT, 0, wait );
		}else{
			Snd_PMVoiceWaitPlay( wk->pd->mons, wait, wk->pd->frm );
		}
		wk->voice = FALSE;
	}

	pat = SoftSprite_FwdAnime( &wk->ssawk );

	if( pat >= 0 ){
		ObjVramTrans( &wk->cgx[pat*POKEGRA_TEX_SIZE], wk->vram, POKEGRA_TEX_SIZE );
	}else{
		sys_FreeMemoryEz( wk );
		TCB_Delete( tcb );
	}
}


//============================================================================================
//	シーン２
//============================================================================================

//--------------------------------------------------------------------------------------------
/**
 * シーン２：アルファブレンド設定
 *
 * @param	wk		画面ワーク
 * @param	frame	フレーム数
 * @param	cnt		現在のカウント
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void Scene02StartBlend( DEMO_WORK * wk, u32 frame, u32 cnt )
{
	if( frame == cnt ){
	    G2_SetBlendAlpha(
			GX_BLEND_PLANEMASK_NONE,
			GX_BLEND_PLANEMASK_BG2 | GX_BLEND_PLANEMASK_BG3 | GX_BLEND_PLANEMASK_OBJ,
			0, 0 );
	}else{
		u32	prm = ( ( 16 << 16 ) / frame * cnt ) >> 16;

	    G2_SetBlendAlpha(
			GX_BLEND_PLANEMASK_BG2,
			GX_BLEND_PLANEMASK_BG2 | GX_BLEND_PLANEMASK_BG3 | GX_BLEND_PLANEMASK_OBJ,
			prm, 16 - prm );
	}
}

//--------------------------------------------------------------------------------------------
/**
 * シーン２：動作メイン処理
 *
 * @param	wk		画面ワーク
 *
 * @retval	"1 = 処理中"
 * @retval	"0 = それ以外"
 */
//--------------------------------------------------------------------------------------------
static int VFunc2ndSceneMain( DEMO_WORK * wk )
{
	if( wk->bg_scroll_flg == 1 ){
		GF_BGL_ScrollReq( wk->bgl, GF_BGL_FRAME2_M, GF_BGL_SCROLL_X_DEC, S2_BG2_SCROLL_SPD );
	}
	if( wk->flash_flg == 1 ){
		if( wk->s2_flash_cnt == wk->s2_flash_wait ){
			s16	x, y;
			x = gf_rand() % S2_FLASH_X_SIZ + S2_FLASH_X_MIN;
			y = gf_rand() % S2_FLASH_Y_SIZ + S2_FLASH_Y_MIN;
			CATS_ObjectPosSetCap( wk->cap[OBJID_2ND_FLASH], x, y );
			ObjAnmSet( wk, OBJID_2ND_FLASH, 0 );
			wk->s2_flash_wait = gf_rand() % S2_FLASH_WAIT_MAX + S2_FLASH_WAIT_MIN;
			wk->s2_flash_cnt  = 0;
		}else{
			wk->s2_flash_cnt++;
		}
	}

	switch( wk->vseq ){
	case S2_SUBSEQ_INIT_WAIT:		// 初期ウェイト
		if( wk->vcnt == S2_INIT_WAIT ){
			wk->vcnt = 0;
			wk->vseq++;
		}else{
			wk->vcnt++;
		}
		break;

	case S2_SUBSEQ_POKE_IN:			// ポケモンイン
		PokeMove(
			wk->cap[OBJID_2ND_POKE1+wk->mv_poke],
			&Scene02PokeMoveData[wk->mv_poke], S2_POKEIN_FRM, wk->vcnt );
		if( wk->vcnt == S2_POKEIN_FRM ){
			CATS_ObjectAffineSetCap( wk->cap[OBJID_2ND_POKE1+wk->mv_poke], CLACT_AFFINE_NORMAL );
			wk->mv_poke++;
			wk->vcnt = 0;
			if( wk->mv_poke == TEMOTI_POKEMAX ){
				wk->mv_poke = 0;
				wk->vseq++;
			}
		}else{
			wk->vcnt++;
		}
		break;

	case S2_SUBSEQ_POKE_IN_WAIT:	// インした後のウェイト
		if( wk->vcnt == S2_POKEIN_WAIT ){
			wk->vcnt = 0;
			wk->vseq++;
		}else{
			wk->vcnt++;
		}
		break;

	case S2_SUBSEQ_EFF_START:		// ホワイトインセット＆文字面表示＆主人公表示＆３Ｄエフェクト開始
		wk->s2_wf_div = S2_EFF_START_WF_DIV;
		wk->fade_flg = 1;
		wk->eff_flg = 1;
		wk->bg_scroll_flg = 1;
		wk->flash_flg = 1;
		CATS_ObjectEnableCap( wk->cap[OBJID_2ND_FLASH], 1 );
		wk->vseq++;
		break;

	case S2_SUBSEQ_ST_SDW_MV:
		Scene02StartBlend( wk, S2_START_SHADOW_MV_FRM, wk->vcnt );
		{
			u32	i;

			for( i=0; i<wk->pokeCount; i++ ){
				PokeMove(
					wk->cap[OBJID_2ND_POKE_S1+i],
					&Scene02ShadowMove[i], S2_START_SHADOW_MV_FRM, wk->vcnt );
			}
			PokeMove(
				wk->cap[OBJID_2ND_PLAYER_S],
				&Scene02ShadowMove[TEMOTI_POKEMAX], S2_START_SHADOW_MV_FRM, wk->vcnt );
		}
		if( wk->vcnt == S2_START_SHADOW_MV_FRM ){
			wk->vcnt = 0;
			wk->vseq++;
		}else{
			wk->vcnt++;
		}
		break;

	case S2_SUBSEQ_MAIN:			// メイン
		if( WIPE_SYS_EndCheck() == TRUE ){
			if( ( sys.trg & (PAD_BUTTON_DECIDE|PAD_BUTTON_CANCEL) ) || GF_TP_GetTrg() == TRUE ){
				wk->s2_wf_div = S2_END_BO_DIV;
				wk->fade_flg = 1;
				wk->vseq++;
			}
		}
		break;

	case S2_SUBSEQ_END_FADE_OUT:
		Scene02StartBlend( wk, S2_END_FADE_FRM, wk->vcnt );
		if( wk->vcnt == S2_END_FADE_FRM_HALF ){
			if( WIPE_SYS_EndCheck() == TRUE ){
				wk->s2_wf_div = S2_END_BO_DIV;
				wk->fo_flg = 1;
				wk->vseq++;
			}
		}else{
			wk->vcnt++;
		}

	case S2_SUBSEQ_END:
		{
			u32	i;

			for( i=0; i<wk->pokeCount; i++ ){
				PokeMove(
					wk->cap[OBJID_2ND_POKE1+i],
					&Scene02EndObjMove[i], S2_END_FADE_FRM, wk->vcnt );
				PokeMove(
					wk->cap[OBJID_2ND_POKE_S1+i],
					&Scene02EndObjSMove[i], S2_END_FADE_FRM, wk->vcnt );
			}
			PokeMove(
				wk->cap[OBJID_2ND_PLAYER],
				&Scene02EndObjMove[TEMOTI_POKEMAX], S2_END_FADE_FRM, wk->vcnt );
			PokeMove(
				wk->cap[OBJID_2ND_PLAYER_S],
				&Scene02EndObjSMove[TEMOTI_POKEMAX], S2_END_FADE_FRM, wk->vcnt );
		}
		if( wk->vseq == S2_SUBSEQ_END ){
			if( wk->vcnt == S2_END_FADE_FRM ){
				if( WIPE_SYS_EndCheck() == TRUE ){
					wk->vcnt = 0;
					wk->vseq = 0;
					return 0;
				}
			}else{
				wk->vcnt++;
			}
		}
	}

	return 1;
}

//--------------------------------------------------------------------------------------------
/**
 * シーン２：フェードイン設定
 *
 * @param	wk		画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void Scene02FadeSet( DEMO_WORK * wk )
{
	WIPE_SYS_Start(
		WIPE_PATTERN_M, WIPE_TYPE_FADEIN, WIPE_TYPE_FADEIN,
		WIPE_FADE_WHITE, wk->s2_wf_div, 1, HEAPID_DENDOU_DEMO );
}

//--------------------------------------------------------------------------------------------
/**
 * シーン２：フェードアウト設定
 *
 * @param	wk		画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void Scene02FadeOutSet( DEMO_WORK * wk )
{
	WIPE_SYS_Start(
		WIPE_PATTERN_WMS, WIPE_TYPE_FADEOUT, WIPE_TYPE_FADEOUT,
		WIPE_FADE_BLACK, wk->s2_wf_div, 1, HEAPID_DENDOU_DEMO );
}

//--------------------------------------------------------------------------------------------
/**
 * シーン２：VBLANK関数
 *
 * @param	tcb		TCB
 * @param	work	画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void Scene02VBlankFunc( TCB_PTR tcb, void * work )
{
	DEMO_WORK * wk = work;

	if( wk->vfunk != NULL ){
		pDendouDemoFunc func = wk->vfunk;
		if( func( wk ) == 0 ){
			wk->vfunk = NULL;
		}
	}

	Scene02Main3D( wk );

	GF_BGL_VBlankFunc( wk->bgl );

	CATS_Draw( wk->crp );
	CATS_RenderOamTrans();

	OS_SetIrqCheckFlag( OS_IE_V_BLANK );
}

//--------------------------------------------------------------------------------------------
/**
 * シーン２：ＢＧ初期化
 *
 * @param	wk		画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void Scene02BgInit( DEMO_WORK * wk )
{
	{	// BG SYSTEM
		GF_BGL_SYS_HEADER sysh = {
			GX_DISPMODE_GRAPHICS, GX_BGMODE_0, GX_BGMODE_0, GX_BG0_AS_3D,
		};
		GF_BGL_InitBG( &sysh );
	}

	{	// メイン画面：文字面
		GF_BGL_BGCNT_HEADER cnth= {
			0, 0, 0x800, 0, GF_BGL_SCRSIZ_256x256, GX_BG_COLORMODE_16,
			GX_BG_SCRBASE_0xf800, GX_BG_CHARBASE_0x00000, GX_BG_EXTPLTT_01,
			0, 0, 0, FALSE
		};
		GF_BGL_BGControlSet( wk->bgl, GF_BGL_FRAME1_M, &cnth, GF_BGL_MODE_TEXT );
		GF_BGL_ScrClear( wk->bgl, GF_BGL_FRAME1_M );
		GF_BGL_ClearCharSet( GF_BGL_FRAME1_M, 0x20, 0, HEAPID_DENDOU_DEMO );
	}
	{	// メイン画面：背景１
		GF_BGL_BGCNT_HEADER cnth= {
			0, 0, 0x800, 0, GF_BGL_SCRSIZ_256x256, GX_BG_COLORMODE_16,
			GX_BG_SCRBASE_0xf000, GX_BG_CHARBASE_0x10000, GX_BG_EXTPLTT_01,
			2, 0, 0, FALSE
		};
		GF_BGL_BGControlSet( wk->bgl, GF_BGL_FRAME2_M, &cnth, GF_BGL_MODE_TEXT );
	}
	{	// メイン画面：背景２
		GF_BGL_BGCNT_HEADER cnth= {
			0, 0, 0x800, 0, GF_BGL_SCRSIZ_256x256, GX_BG_COLORMODE_16,
			GX_BG_SCRBASE_0xe800, GX_BG_CHARBASE_0x10000, GX_BG_EXTPLTT_01,
			3, 0, 0, FALSE
		};
		GF_BGL_BGControlSet( wk->bgl, GF_BGL_FRAME3_M, &cnth, GF_BGL_MODE_TEXT );
	}

	GF_Disp_GX_VisibleControl( GX_PLANEMASK_BG1, VISIBLE_OFF );
	GF_Disp_GX_VisibleControl( GX_PLANEMASK_BG2, VISIBLE_OFF );
	GF_Disp_GX_VisibleControl( GX_PLANEMASK_BG3, VISIBLE_OFF );
}

//--------------------------------------------------------------------------------------------
/**
 * シーン２：ＢＧ削除
 *
 * @param	wk		画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void Scene02BgExit( DEMO_WORK * wk )
{
	GF_BGL_BGControlExit( wk->bgl, GF_BGL_FRAME3_M );
	GF_BGL_BGControlExit( wk->bgl, GF_BGL_FRAME2_M );
	GF_BGL_BGControlExit( wk->bgl, GF_BGL_FRAME1_M );
	GF_BGL_BGControlExit( wk->bgl, GF_BGL_FRAME0_M );
}

//--------------------------------------------------------------------------------------------
/**
 * シーン２：ＢＧグラフィック読み込み
 *
 * @param	wk		画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void Scene02BgGraphicLoad( DEMO_WORK * wk )
{
	ArcUtil_HDL_ScrnSet(
		wk->ah, NARC_dendou_demo_scene2_bg02_lz_NSCR,
		wk->bgl, GF_BGL_FRAME2_M, 0, 0, TRUE, HEAPID_DENDOU_DEMO );
	ArcUtil_HDL_ScrnSet(
		wk->ah, NARC_dendou_demo_scene2_bg03_lz_NSCR,
		wk->bgl, GF_BGL_FRAME3_M, 0, 0, TRUE, HEAPID_DENDOU_DEMO );

	ArcUtil_HDL_BgCharSet(
		wk->ah, NARC_dendou_demo_scene2_bg_lz_NCGR,
		wk->bgl, GF_BGL_FRAME2_M, 0, 0, TRUE, HEAPID_DENDOU_DEMO );

	ArcUtil_HDL_PalSet(
		wk->ah, NARC_dendou_demo_scene2_bg_NCLR, PALTYPE_MAIN_BG, 0, 0x20, HEAPID_DENDOU_DEMO );

	// 上画面のバックグラウンドカラー設定
	GF_BGL_BackGroundColorSet( GF_BGL_FRAME1_M, 0 );
}

//--------------------------------------------------------------------------------------------
/**
 * シーン２：ＢＭＰ初期化
 *
 * @param	wk		画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void Scene02BmpInit( DEMO_WORK * wk )
{
	u32	i;

	for( i=0; i<S2_BMPWIN_MAX; i++ ){
		GF_BGL_BmpWinAddEx( wk->bgl, &wk->win[i], &Scene02BmpWinData[i] );
	}

	//「おめでとう」
	GF_BGL_BmpWinDataFill( &wk->win[S2_BMPWIN_MESSAGE], 1 );
	MSGMAN_GetString( wk->mman, str_dendemo_cong2, wk->tmpbuf1 );
	GF_STR_PrintColor(
		&wk->win[S2_BMPWIN_MESSAGE], FONT_SYSTEM, wk->tmpbuf1,
		128 - ( FontProc_GetPrintStrWidth(FONT_SYSTEM,wk->tmpbuf1,0) / 2 ), 0,
		MSG_NO_PUT, FCOL_WN15, NULL );
	GF_BGL_BmpWinOn( &wk->win[S2_BMPWIN_MESSAGE] );

	// 時間など
	GF_BGL_BmpWinDataFill( &wk->win[S2_BMPWIN_DATA], 1 );
	MSGMAN_GetString( wk->mman, str_dendemo_player1, wk->tmpbuf2 );
	WORDSET_RegisterPlayerName( wk->wset, 0, wk->prm->player );
	WORDSET_RegisterNumber( wk->wset, 1, MyStatus_GetID_Low(wk->prm->player),   5, NUMBER_DISPTYPE_ZERO, NUMBER_CODETYPE_DEFAULT );
	WORDSET_RegisterNumber( wk->wset, 2, PLAYTIME_GetHour(wk->prm->playTime),   3, NUMBER_DISPTYPE_LEFT, NUMBER_CODETYPE_DEFAULT );
	WORDSET_RegisterNumber( wk->wset, 3, PLAYTIME_GetMinute(wk->prm->playTime), 2, NUMBER_DISPTYPE_ZERO, NUMBER_CODETYPE_DEFAULT );
	WORDSET_ExpandStr( wk->wset, wk->tmpbuf1, wk->tmpbuf2 );
	GF_STR_PrintColor(
		&wk->win[S2_BMPWIN_DATA], FONT_SYSTEM, wk->tmpbuf1,
		128 - ( FontProc_GetPrintStrWidth(FONT_SYSTEM,wk->tmpbuf1,0) / 2 ), 0,
		MSG_NO_PUT, FCOL_WN15, NULL );
	GF_BGL_BmpWinOn( &wk->win[S2_BMPWIN_DATA] );
}

//--------------------------------------------------------------------------------------------
/**
 * シーン２：ＢＭＰ削除
 *
 * @param	wk		画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void Scene02BmpExit( DEMO_WORK * wk )
{
	u32	i;

	for( i=0; i<S2_BMPWIN_MAX; i++ ){
		GF_BGL_BmpWinDel( &wk->win[i] );
	}
}

//--------------------------------------------------------------------------------------------
/**
 * シーン２：ＯＢＪ初期化
 *
 * @param	wk		画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void Scene02ObjInit( DEMO_WORK * wk )
{
	ARCHANDLE * ah;
	NNSG2dImageProxy * ipc;
	NNSG2dImagePaletteProxy * ipp;
	void * buf;
	TR_CLACT_GRA	tcg;
	u32	cgx;
	u32	pal;
	u32	i;
	CHANGES_INTO_DATA_RECT rect = { POKE_TEX_X, POKE_TEX_Y, POKE_TEX_W, POKE_TEX_H };

	// リソース読み込み
	ah = ArchiveDataHandleOpen( ARC_BATT_OBJ, HEAPID_DENDOU_DEMO );

	CATS_LoadResourceCellArcH( wk->csp, wk->crp, ah, POKE_OAM_NCER, 0, CEL_ID_POKEGRA1 );
	CATS_LoadResourceCellAnmArcH( wk->csp, wk->crp, ah, POKE_OAM_NANR, 0, ANM_ID_POKEGRA1 );

	// ポケモン
	for( i=0; i<TEMOTI_POKEMAX; i++ ){
		CATS_LoadResourceCharArcH(
			wk->csp, wk->crp, ah,
			POKE_OAM_NCGR, 0, NNS_G2D_VRAM_TYPE_2DMAIN, CHR_ID_POKEGRA1+i );
		CATS_LoadResourcePlttArcH(
			wk->csp, wk->crp, ah,
			POKE_OAM_NCLR, 0, 1, NNS_G2D_VRAM_TYPE_2DMAIN, PAL_ID_POKEGRA1+i );
	}

	// プレイヤー
	CATS_LoadResourceCharArcH(
		wk->csp, wk->crp, ah,
		POKE_OAM_NCGR, 0, NNS_G2D_VRAM_TYPE_2DMAIN, CHR_ID_PLAYER );
	CATS_LoadResourcePlttArcH(
		wk->csp, wk->crp, ah,
		POKE_OAM_NCLR, 0, 1, NNS_G2D_VRAM_TYPE_2DMAIN, PAL_ID_PLAYER );

	// 影用パレット
	CATS_LoadResourcePlttArcH(
		wk->csp, wk->crp, ah,
		POKE_OAM_NCLR, 0, 1, NNS_G2D_VRAM_TYPE_2DMAIN, PAL_ID_SHADOW );

	ArchiveDataHandleClose( ah );

	// 光
	CATS_LoadResourceCellArcH(
		wk->csp, wk->crp, wk->ah, NARC_dendou_demo_flash_obj_lz_NCER, 1, CEL_ID_FLASH );
	CATS_LoadResourceCellAnmArcH(
		wk->csp, wk->crp, wk->ah, NARC_dendou_demo_flash_obj_lz_NANR, 1, ANM_ID_FLASH );
	CATS_LoadResourceCharArcH(
		wk->csp, wk->crp, wk->ah,
		NARC_dendou_demo_flash_obj_lz_NCGR, 1, NNS_G2D_VRAM_TYPE_2DMAIN, CHR_ID_FLASH );
	CATS_LoadResourcePlttArcH(
		wk->csp, wk->crp, wk->ah,
		NARC_dendou_demo_flash_obj_NCLR, 0, 1, NNS_G2D_VRAM_TYPE_2DMAIN, PAL_ID_FLASH );


	// セルアクター追加
	// ポケモン
	for( i=0; i<TEMOTI_POKEMAX; i++ ){
		wk->cap[OBJID_2ND_POKE1+i]   = CATS_ObjectAdd_S(
										wk->csp, wk->crp, &Cla2ndScenePrm[OBJID_2ND_POKE1+i] );
		wk->cap[OBJID_2ND_POKE_S1+i] = CATS_ObjectAdd_S(
										wk->csp, wk->crp, &Cla2ndScenePrm[OBJID_2ND_POKE_S1+i] );
		if( i < wk->pokeCount ){
			PokeGraChange( wk, &wk->poke[i], PARA_FRONT, OBJID_2ND_POKE1+i );
		}else{
			CATS_ObjectEnableCap( wk->cap[OBJID_2ND_POKE1+i], 0 );
		}
		PokePaletteGet( wk, i, OBJID_2ND_POKE1+i );
		PokeShadowColSet( wk, OBJID_2ND_POKE1+i, SHADOW_COL_WHITE );

//		CATS_ObjectAffineSetCap( wk->cap[OBJID_2ND_POKE1+i], CLACT_AFFINE_DOUBLE );
		CATS_ObjectAffineSetCap( wk->cap[OBJID_2ND_POKE1+i], CLACT_AFFINE_NORMAL );
		CATS_ObjectScaleSetCap( wk->cap[OBJID_2ND_POKE1+i], 1.0, 1.0 );

		CATS_ObjectObjModeSetCap( wk->cap[OBJID_2ND_POKE1+i], GX_OAM_MODE_NORMAL );
		CATS_ObjectObjModeSetCap( wk->cap[OBJID_2ND_POKE_S1+i], GX_OAM_MODE_XLU );

		CATS_ObjectEnableCap( wk->cap[OBJID_2ND_POKE_S1+i], 0 );
	}

	// プレイヤー
	wk->cap[OBJID_2ND_PLAYER]   = CATS_ObjectAdd_S( wk->csp, wk->crp, &Cla2ndScenePrm[OBJID_2ND_PLAYER] );
	wk->cap[OBJID_2ND_PLAYER_S] = CATS_ObjectAdd_S( wk->csp, wk->crp, &Cla2ndScenePrm[OBJID_2ND_PLAYER_S] );
	CATS_ObjectAffineSetCap( wk->cap[OBJID_2ND_PLAYER], CLACT_AFFINE_NORMAL );
	CATS_ObjectAffineSetCap( wk->cap[OBJID_2ND_PLAYER_S], CLACT_AFFINE_NORMAL );
	CATS_ObjectEnableCap( wk->cap[OBJID_2ND_PLAYER], 0 );
	CATS_ObjectEnableCap( wk->cap[OBJID_2ND_PLAYER_S], 0 );

	if( MyStatus_GetMySex(wk->prm->player) == PM_FEMALE ){
		TrCLACTGraDataGet( TRTYPE_GIRL, PARA_FRONT, &tcg );
	}else{
		TrCLACTGraDataGet( TRTYPE_BOY, PARA_FRONT, &tcg );
	}

	buf = sys_AllocMemory( HEAPID_DENDOU_DEMO, POKEGRA_TEX_SIZE*2 );
	ChangesInto_OAM_from_PokeTex_RC( tcg.arcID, tcg.ncbrID, HEAPID_DENDOU_DEMO, &rect, buf );
	ipc = CLACT_ImageProxyGet(wk->cap[OBJID_2ND_PLAYER]->act);
	cgx = NNS_G2dGetImageLocation( ipc, NNS_G2D_VRAM_TYPE_2DMAIN );
	ObjVramTrans( buf, cgx, POKEGRA_TEX_SIZE );
	sys_FreeMemoryEz( buf );

	ipp = CLACT_PaletteProxyGet( wk->cap[OBJID_2ND_PLAYER]->act );
	pal = NNS_G2dGetImagePaletteLocation( ipp, NNS_G2D_VRAM_TYPE_2DMAIN );
	ArcUtil_PalSet(
		tcg.arcID, tcg.nclrID, PALTYPE_MAIN_OBJ, pal, POKEGRA_PAL_SIZE, HEAPID_DENDOU_DEMO );

	// 光
	wk->cap[OBJID_2ND_FLASH] = CATS_ObjectAdd_S( wk->csp, wk->crp, &Cla2ndScenePrm[OBJID_2ND_FLASH] );
	CATS_ObjectEnableCap( wk->cap[OBJID_2ND_FLASH], 0 );

	// パレット変更
	PokeShadowColSet( wk, OBJID_2ND_PLAYER_S, SHADOW_COL_BLACK );

	GF_Disp_GX_VisibleControl( GX_PLANEMASK_OBJ, VISIBLE_ON );
}

//--------------------------------------------------------------------------------------------
/**
 * シーン２：ＯＢＪ削除
 *
 * @param	wk		画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void Scene02ObjExit( DEMO_WORK * wk )
{
	u32	i;

	for( i=0; i<OBJID_MAX; i++ ){
		ObjDel( wk, i );
	}

	CATS_FreeResourcePltt( wk->crp, PAL_ID_FLASH );
	CATS_FreeResourceChar( wk->crp, CHR_ID_FLASH );
	CATS_FreeResourceCell( wk->crp, CEL_ID_FLASH );
	CATS_FreeResourceCellAnm( wk->crp, ANM_ID_FLASH );

	CATS_FreeResourcePltt( wk->crp, PAL_ID_PLAYER );
	CATS_FreeResourceChar( wk->crp, CHR_ID_PLAYER );

	for( i=0; i<TEMOTI_POKEMAX; i++ ){
		CATS_FreeResourcePltt( wk->crp, PAL_ID_POKEGRA1+i );
		CATS_FreeResourceChar( wk->crp, CHR_ID_POKEGRA1+i );
	}
	CATS_FreeResourceCell( wk->crp, CEL_ID_POKEWALK1 );
	CATS_FreeResourceCellAnm( wk->crp, ANM_ID_POKEWALK1 );
}

//--------------------------------------------------------------------------------------------
/**
 * シーン２：３Ｄ初期化
 *
 * @param	wk		画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void Scene02Init3D( DEMO_WORK * wk )
{
	// NitroSystem:３Ｄエンジンの初期化
	NNS_G3dInit();
	// マトリクススタックの初期化
    G3X_InitMtxStack();

	// 各種描画モードの設定(シェード＆アンチエイリアス＆半透明)
    G3X_SetShading(GX_SHADING_TOON);
    G3X_AntiAlias(TRUE);

	G3X_AlphaTest(FALSE, 0);	// アルファテスト　　オフ
	G3X_AlphaBlend(TRUE);		// アルファブレンド　オン

	// クリアカラーの設定
    G3X_SetClearColor(GX_RGB(0, 0, 0),	// clear color
                      0,				// clear alpha
                      0x7fff,			// clear depth
                      63,				// clear polygon ID
                      FALSE				// fog
                      );

	// ジオメトリエンジン起動後必ず呼ばれなければならない
    G3_SwapBuffers(GX_SORTMODE_AUTO, GX_BUFFERMODE_W);

	// ビューポートの設定
    G3_ViewPort(0, 0, 255, 191);

    GF_G3D_InitFrmTexVramManager(1, TRUE);
    GF_G3D_InitFrmPlttVramManager(0x4000, TRUE);

	// ３Ｄ使用面の設定(表示＆プライオリティー)
	GF_Disp_GX_VisibleControl( GX_PLANEMASK_BG0, VISIBLE_ON );
    G2_SetBG0Priority(1);
    G2_SetBlendAlpha(
		GX_BLEND_PLANEMASK_NONE,
		GX_BLEND_PLANEMASK_BG2 | GX_BLEND_PLANEMASK_BG3 | GX_BLEND_PLANEMASK_OBJ,
		0, 0 );

	Scene02InitCamera( wk );
}

//--------------------------------------------------------------------------------------------
/**
 * シーン２：カメラ初期化
 *
 * @param	wk		画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void Scene02InitCamera( DEMO_WORK* wk )
{
	enum {
		CAMERA_PEARCE	= FX_GET_ROTA_NUM(22),
		CAMERA_DISTANCE	= (5 << FX32_SHIFT)
	};
	VecFx32 up;

	wk->camera = GFC_AllocCamera( HEAPID_DENDOU_DEMO );

	wk->cameraTarget.x = 0;
	wk->cameraTarget.y = 0;
	wk->cameraTarget.z = 0;

	wk->cameraAngle.x = FX_GET_ROTA_NUM(0);
	wk->cameraAngle.y = FX_GET_ROTA_NUM(0);
	wk->cameraAngle.z = FX_GET_ROTA_NUM(0);

	GFC_InitCameraTDA(
			&(wk->cameraTarget),
			CAMERA_DISTANCE,
			&(wk->cameraAngle),
			CAMERA_PEARCE,
			GF_CAMERA_PERSPECTIV,
			TRUE,
			wk->camera
	);

	up.x = 0;
	up.y = FX32_ONE;
	up.z = 0;
	GFC_SetCamUp( &up, wk->camera );

	GFC_AttachCamera( wk->camera );

	GFC_SetCameraClip( (1<<FX32_SHIFT), (500<<FX32_SHIFT), wk->camera );
}

//--------------------------------------------------------------------------------------------
/**
 * シーン２：３Ｄ削除
 *
 * @param	wk		画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void Scene02Exit3D( DEMO_WORK * wk )
{
	GFC_FreeCamera( wk->camera );
}

//--------------------------------------------------------------------------------------------
/**
 * シーン２：３Ｄメイン
 *
 * @param	wk		画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void Scene02Main3D( DEMO_WORK * wk )
{
	if( G3X_IsGeometryBusy() ){
		return;
	}

	G3X_Reset();

	NNS_G3dGePushMtx();
	DrawLight( wk->lightTask );
	NNS_G3dGePopMtx(1);

	NNS_G3dGePushMtx();
	DrawConfetti( wk->confettiTask );
	NNS_G3dGePopMtx(1);

	G3_SwapBuffers( GX_SORTMODE_MANUAL, GX_BUFFERMODE_Z );
}


//===============================================================================================
/**
	↓↓↓ シーン２のライトと紙吹雪はPLのコピペ ↓↓↓
 */
//===============================================================================================

//-----------------------------------------------------------------------------------------------
// ライトポリゴン動かし
//-----------------------------------------------------------------------------------------------
enum {
	LIGHT_MAX = 8,

	CMD_BUFFER_LEN = 64,
	LIGHT_ORG_WIDTH = 0x50,
	LIGHT_ANGLE_MIN = 10 << FX32_SHIFT,
	LIGHT_ANGLE_MAX = 170 << FX32_SHIFT,
	LIGHT_ANGLE_RANGE = LIGHT_ANGLE_MAX - LIGHT_ANGLE_MIN,

};

enum {
	LIGHT_END_WIDTH = 0x240,
	LIGHT_LEN = 0x2800,
};

typedef struct {
	GXDLInfo	cmdInfo;
	u32			cmdBuffer[ CMD_BUFFER_LEN * LIGHT_MAX ];
	u32			cmdSize;

	TCB_PTR		tcb[LIGHT_MAX];
	TCB_PTR		tailTask;
	int			cnt;

	DEMO_WORK*	mainWk;
}LIGHT_CTRL_TASK_WORK;


typedef struct {
	GXDLInfo*	cmdInfo;
	u32			cmdBuffer[ CMD_BUFFER_LEN * LIGHT_MAX ];
	u32			cmdSize;

	fx32		angle;
	fx32		angleSpeed;
	int			color;
	int			id;

	fx16		cx;
	VecFx16		vtxP1;
	VecFx16		vtxP2;
	VecFx16		vtxD1;
	VecFx16		vtxD2;

	DEMO_WORK*  mainWk;

}LIGHT_TASK_WORK;

static TCB_PTR CreateLightTask( LIGHT_CTRL_TASK_WORK* ctrlTask, fx16 px, fx32 angle, int id );
static void inline calc_light_endpos( LIGHT_TASK_WORK* wk );

static void LightCtrlTask( TCB_PTR tcb, void * work );
static void LightCtrlTailTask( TCB_PTR tcb, void * work );
static void LightTask( TCB_PTR tcb, void * work );

static u32  LightTaskCount = 0;
static BOOL LightTaskEnable = TRUE;

static TCB_PTR CreateLightCtrlTask( DEMO_WORK * wk )
{
	LIGHT_CTRL_TASK_WORK * twk;
	TCB_PTR	tcb;

	twk = sys_AllocMemory( HEAPID_DENDOU_DEMO, sizeof(LIGHT_CTRL_TASK_WORK) );

	LightTaskEnable = TRUE;
	LightTaskCount = 2;

	twk->cnt = 0;
	twk->tailTask = VIntrTCB_Add( LightCtrlTailTask, twk, S2_TASKPRI_LIGHT_CTRL_TAIL );
	twk->mainWk = wk;

	return VIntrTCB_Add( LightCtrlTask, twk, S2_TASKPRI_LIGHT_CTRL );
}

static void LightCtrlTask( TCB_PTR tcb, void * work )
{
	if( LightTaskEnable ){
		LIGHT_CTRL_TASK_WORK * wk = work;

		G3_BeginMakeDL( &wk->cmdInfo, wk->cmdBuffer, sizeof(wk->cmdBuffer) );

		G3B_MaterialColorDiffAmb(	&wk->cmdInfo,
									GX_RGB(31, 31, 31),	// diffuse
									GX_RGB(16, 16, 16),	// ambient
									FALSE				// use diffuse as vtx color if TRUE
		);

		G3B_MaterialColorSpecEmi(	&wk->cmdInfo,
									GX_RGB(16, 16, 16),	// specular
									GX_RGB(0, 0, 0),	// emission
									FALSE				// use shininess table if TRUE
		);
	}else{
		LightTaskCount--;
		TCB_Delete( tcb );
	}
}

static void LightCtrlTailTask( TCB_PTR tcb, void * work )
{
	if( LightTaskEnable ){
		LIGHT_CTRL_TASK_WORK * wk = work;

		wk->cmdSize = G3_EndMakeDL( &wk->cmdInfo );
		DC_FlushRange( wk->cmdBuffer, wk->cmdSize );
	}else{
		LightTaskCount--;
		TCB_Delete( tcb );
	}
}

static void AddLightTask( TCB_PTR ctrlTask, fx16 px, fx32 angle )
{
	LIGHT_CTRL_TASK_WORK * twk = TCB_GetWork( ctrlTask );

	if( twk->cnt < LIGHT_MAX ){
		twk->tcb[twk->cnt] = CreateLightTask( twk, px, angle, twk->cnt );
		LightTaskCount++;
		twk->cnt++;
	}
}


static TCB_PTR CreateLightTask( LIGHT_CTRL_TASK_WORK * ctrlTask, fx16 px, fx32 angle, int id )
{
	static const int col[] = {
		GX_RGB(31,31,12),
		GX_RGB(31,31,16),
		GX_RGB(31,28,8),
		GX_RGB(31,31,12),
		GX_RGB(31,31,16),
		GX_RGB(31,28,8),
		GX_RGB(31,31,12),
		GX_RGB(31,31,12),
	};
	static const fx16 speed[] = {
		0x0c00,
		0x0b00,
		0x0a00,
		0x0c00,
		0x0b00,
		0x0a00,
	};

	LIGHT_TASK_WORK* twk = sys_AllocMemory( HEAPID_DENDOU_DEMO, sizeof(LIGHT_TASK_WORK) );

	twk->cmdInfo = &(ctrlTask->cmdInfo);
	twk->cx = px;
	twk->color = col[id];
	twk->cmdSize = 0;
	twk->angle = angle;
	twk->angleSpeed = speed[id] * 2;
	twk->id = id;
	VEC_Fx16Set( &(twk->vtxP1), px - LIGHT_ORG_WIDTH, -FX16_ONE, 0 );
	VEC_Fx16Set( &(twk->vtxP2), px + LIGHT_ORG_WIDTH, -FX16_ONE, 0 );
	return VIntrTCB_Add( LightTask, twk, S2_TASKPRI_LIGHT );
}

static void inline calc_light_endpos( LIGHT_TASK_WORK * wk )
{
	int angle = wk->angle >> FX32_SHIFT;
	fx32 cx, cy;

	cx = wk->cx + FX_Mul(_Cos360(angle), LIGHT_LEN);
	cy = FX_Mul(_Sin360(angle), LIGHT_LEN) - FX16_ONE;

	VEC_Fx16Set( &(wk->vtxD1), cx-LIGHT_END_WIDTH, cy, 0 );
	VEC_Fx16Set( &(wk->vtxD2), cx+LIGHT_END_WIDTH, cy, 0 );
}

static void LightTask( TCB_PTR tcb, void * work )
{
	if( LightTaskEnable ){
		LIGHT_TASK_WORK *  wk = work;
		wk->angle += wk->angleSpeed;

		if( wk->angleSpeed > 0 ){
			if( wk->angle >= LIGHT_ANGLE_MAX ){
				wk->angleSpeed *= -1;
			}
		}else{
			if( wk->angle <= LIGHT_ANGLE_MIN ){
				wk->angleSpeed *= -1;
			}
		}

		calc_light_endpos( wk );

		G3B_PolygonAttr(	wk->cmdInfo, GX_LIGHTMASK_NONE,	// disable lights
							GX_POLYGONMODE_MODULATE,			// modulation mode
							GX_CULL_BACK,  // cull back
							wk->id,				// polygon ID(0 - 63)
							16,            // alpha(0 - 31)
							0              // OR of GXPolygonAttrMisc's value
		);


		G3B_Begin( wk->cmdInfo, GX_BEGIN_QUADS );
		{
			G3B_Color( wk->cmdInfo, wk->color );
			G3B_Vtx( wk->cmdInfo, wk->vtxP1.x, wk->vtxP1.y, wk->vtxP1.z );
			G3B_Vtx( wk->cmdInfo, wk->vtxP2.x, wk->vtxP2.y, wk->vtxP2.z );
			G3B_Vtx( wk->cmdInfo, wk->vtxD2.x, wk->vtxD2.y, wk->vtxD2.z );
			G3B_Vtx( wk->cmdInfo, wk->vtxD1.x, wk->vtxD1.y, wk->vtxD1.z );
		}
		G3B_End( wk->cmdInfo );
	}else{
		LightTaskCount--;
		TCB_Delete( tcb );
	}
}


static void DrawLight( TCB_PTR tcb )
{
	if( tcb != NULL ){
		LIGHT_CTRL_TASK_WORK* wk = TCB_GetWork(tcb);

		G3_PushMtx();
		MI_SendGXCommand(3, wk->cmdBuffer, wk->cmdSize);
		G3_PopMtx(1);
	}
}

static void DeleteLightCtrlTask( TCB_PTR tcb )
{
	LightTaskEnable = FALSE;

	if( tcb != NULL ){
		LIGHT_CTRL_TASK_WORK* wk;
		int i;

		wk = TCB_GetWork(tcb);
		for( i=0; i<wk->cnt; i++ ){
			sys_FreeMemoryEz( TCB_GetWork(wk->tcb[i]) );
		}
		sys_FreeMemoryEz( wk );
	}
}

static BOOL WaitLightTaskDelete( void )
{
	return (LightTaskCount == 0);
}

//-----------------------------------------------------------------------------------------------
// 紙吹雪ポリゴン動かし
//-----------------------------------------------------------------------------------------------
enum {
	CONFETTI_MAX = 48,

	CONFETTI_X_MIN = FX16_CONST(-1),
	CONFETTI_X_MAX = FX16_CONST(1),
	CONFETTI_Z_MIN = FX16_CONST(-0.08f),
	CONFETTI_Z_MAX = FX16_CONST(0.08f),
	CONFETTI_Y_MIN = FX16_CONST(-1),
	CONFETTI_Y_MAX   = FX16_CONST(1),

	CONFETTI_X_DIFF = CONFETTI_X_MAX-CONFETTI_X_MIN,
	CONFETTI_Y_DIFF = CONFETTI_Y_MAX-CONFETTI_Y_MIN,
	CONFETTI_Z_DIFF = CONFETTI_Z_MAX-CONFETTI_Z_MIN,

	CONFETTI_X_SIZE = FX16_CONST(0.038f),
	CONFETTI_Y_SIZE = FX16_CONST(0.050f),

	CONFETTI_CMD_LEN = 160,
	CONFETTI_FALL_SPEED = CONFETTI_Y_DIFF / 96,

	CONFETTI_X_SPEED_MIN = 0x0200,
	CONFETTI_X_SPEED_MAX = 0x0400,
	CONFETTI_X_SPEED_DIFF = (CONFETTI_X_SPEED_MAX - CONFETTI_X_SPEED_MIN),
	CONFETTI_Y_SPEED_MIN = 0x0200,
	CONFETTI_Y_SPEED_MAX = 0x0400,
	CONFETTI_Y_SPEED_DIFF = (CONFETTI_Y_SPEED_MAX - CONFETTI_Y_SPEED_MIN),
	CONFETTI_Z_SPEED_MIN = 0x0200,
	CONFETTI_Z_SPEED_MAX = 0x0400,
	CONFETTI_Z_SPEED_DIFF = (CONFETTI_Z_SPEED_MAX - CONFETTI_Z_SPEED_MIN),

	CONFETTI_RAND_SEED = 0x3594,
};

typedef struct {
	int		color;
	int		def_color;
	VecFx16		pos[4];
	VecFx16		rot;
	VecFx16		rotSpeed;
	MtxFx44		rotMtx;

	BOOL   drawFlag;
}CONFETTI_WORK;

typedef struct {
	BOOL			drawStartFlag;
	volatile BOOL	transStartFlag;
	CONFETTI_WORK	confetti[CONFETTI_MAX];

	GXDLInfo	cmdInfo;
	u32			cmdBuffer[ CONFETTI_CMD_LEN * CONFETTI_MAX ];
	u32			cmdSize;

	int			controlPos;

	MtxFx44		current;

}CONFETTI_CONTROL_WORK;

static void ConfettiControlTask( TCB_PTR tcb, void* wk_adrs );


static TCB_PTR CreateConfettiTask( DEMO_WORK* wk )
{
	static const int color_ptn[] = {
		GX_RGB(16,28,21), GX_RGB(31,16,29), GX_RGB(8,8,31), GX_RGB(6,31,31),
		GX_RGB(31,31,0), GX_RGB(9,31,0), GX_RGB(31,18,0), GX_RGB(22,0,31),
	};
	static const  VecFx16  vtxOfs[4] = {
		{ -CONFETTI_X_SIZE, -CONFETTI_Y_SIZE, 0 },
		{  CONFETTI_X_SIZE, -CONFETTI_Y_SIZE, 0 },
		{  CONFETTI_X_SIZE,  CONFETTI_Y_SIZE, 0 },
		{ -CONFETTI_X_SIZE,  CONFETTI_Y_SIZE, 0 },
	};
	CONFETTI_CONTROL_WORK* cwk;
	int i, j, rand_seed, c;
	s16  x, y, z;

	cwk = sys_AllocMemory( HEAPID_DENDOU_DEMO, sizeof(CONFETTI_CONTROL_WORK) );

	rand_seed = gf_rand();
	gf_srand( CONFETTI_RAND_SEED );

	for(i=0, c=0; i<CONFETTI_MAX; i++)
	{
		cwk->confetti[i].color = color_ptn[c];
		if( ++c >= NELEMS(color_ptn) ){ c = 0; }
		x = CONFETTI_X_MIN + (gf_rand() % CONFETTI_X_DIFF);
		y = CONFETTI_Y_MAX + (gf_rand() % CONFETTI_Y_DIFF);
		z = CONFETTI_Z_MIN + (gf_rand() % CONFETTI_Z_DIFF);

		for(j=0; j<4; j++)
		{
			cwk->confetti[i].pos[j].x = x + vtxOfs[j].x;
			cwk->confetti[i].pos[j].y = y + vtxOfs[j].y;
			cwk->confetti[i].pos[j].z = z + vtxOfs[j].z;

			cwk->confetti[i].rot.x = 0;
			cwk->confetti[i].rot.y = 0;
			cwk->confetti[i].rot.z = 0;
			cwk->confetti[i].rotSpeed.x = CONFETTI_X_SPEED_MIN + gf_rand() % CONFETTI_X_SPEED_DIFF;
			cwk->confetti[i].rotSpeed.y = CONFETTI_Y_SPEED_MIN + gf_rand() % CONFETTI_Y_SPEED_DIFF;
			cwk->confetti[i].rotSpeed.z = CONFETTI_Z_SPEED_MIN + gf_rand() % CONFETTI_Z_SPEED_DIFF;

			MTX_Identity44( &cwk->confetti[i].rotMtx );
			#ifdef PM_DEBUG
			cwk->confetti[i].drawFlag = TRUE;
//			OS_TPrintf("x:%d, y:%d, z:%d\n", cwk->confetti[i].pos[j].x, cwk->confetti[i].pos[j].y, cwk->confetti[i].pos[j].z);
			#endif
		}

		j = gf_rand() & 7;
		while(j--)
		{
			VEC_Fx16Add( &cwk->confetti[i].rot, &cwk->confetti[i].rotSpeed, &cwk->confetti[i].rot );
		}
	}

	gf_srand( rand_seed );

	cwk->drawStartFlag = FALSE;
	cwk->transStartFlag = FALSE;
	cwk->controlPos = 0;

	G3_MtxMode( GX_MTXMODE_POSITION_VECTOR );

	return TCB_Add( ConfettiControlTask, cwk, S2_TASKPRI_CONFETTI_CTRL );

}

static void DeleteConfettiTask( TCB_PTR tcb )
{
	if( tcb )
	{
		sys_FreeMemoryEz( TCB_GetWork( tcb ) );
		TCB_Delete( tcb );
	}
}

static void StartConfettiDraw( TCB_PTR tcb )
{
	if(tcb)
	{
		CONFETTI_CONTROL_WORK* wk = TCB_GetWork( tcb );
		wk->drawStartFlag = TRUE;
	}
}

static void ConfettiControlTask( TCB_PTR tcb, void* wk_adrs )
{
	CONFETTI_CONTROL_WORK* wk = wk_adrs;

	if( wk->drawStartFlag )
	{
		int i, j;

		#if 0
		{
			if( sys.repeat & PAD_KEY_UP )
			{
				if( --(wk->controlPos) < 0 )
				{
					wk->controlPos = CONFETTI_MAX - 1;
				}
				OS_TPrintf("control Pos = %d\n", wk->controlPos );
			}
			if( sys.repeat & PAD_KEY_DOWN )
			{
				if( ++(wk->controlPos) >= CONFETTI_MAX )
				{
					wk->controlPos = 0;
				}
				OS_TPrintf("control Pos = %d\n", wk->controlPos );
			}
			if (sys.trg & PAD_BUTTON_SELECT )
			{
				wk->confetti[ wk->controlPos ].drawFlag ^= 1;
				OS_TPrintf("confetti[ %d ] drawFlag = %d\n", wk->controlPos, wk->confetti[ wk->controlPos ].drawFlag);
			}
			if (sys.trg & PAD_BUTTON_START )
			{
				int j, p;

				p = wk->controlPos;
				OS_TPrintf("confetti[ %d ] vtx ---------------\n", p);
				for(j=0; j<4; j++)
				{
					OS_TPrintf("  x:%d, y:%d, z:%d\n", wk->confetti[p].pos[j].x, wk->confetti[p].pos[j].y, wk->confetti[p].pos[j].z);
				}
				OS_TPrintf("------------------------------\n");
			}
		}
		#endif

	    G3_BeginMakeDL( &wk->cmdInfo, wk->cmdBuffer, sizeof(wk->cmdBuffer) );

		G3B_PolygonAttr(	&wk->cmdInfo, GX_LIGHTMASK_01,	// disable lights
							GX_POLYGONMODE_MODULATE,			// modulation mode
							GX_CULL_NONE, 	// cull back
							63,			// polygon ID(0 - 63)
							31,            // alpha(0 - 31)
							0              // OR of GXPolygonAttrMisc's value
		);

		#if 1
		G3B_MaterialColorDiffAmb(	&wk->cmdInfo,
									GX_RGB(20,20,20),	// diffuse
									GX_RGB(0,0,0),		// ambient
									FALSE				// use diffuse as vtx color if TRUE
		);
		#endif

	    for(i=0; i<CONFETTI_MAX; i++)
	    {
			wk->confetti[i].pos[3].y -= CONFETTI_FALL_SPEED;
			if( wk->confetti[i].pos[3].y <= CONFETTI_Y_MIN )
			{
				wk->confetti[i].pos[3].y = CONFETTI_Y_MAX - (CONFETTI_Y_MIN - wk->confetti[i].pos[3].y);
			}
			wk->confetti[i].pos[0].y = wk->confetti[i].pos[3].y - (CONFETTI_Y_SIZE*2);
			wk->confetti[i].pos[1].y = wk->confetti[i].pos[0].y;
			wk->confetti[i].pos[2].y = wk->confetti[i].pos[3].y;

			VEC_Fx16Add( &wk->confetti[i].rot, &wk->confetti[i].rotSpeed, &wk->confetti[i].rot );
			MTX_Identity44( &(wk->confetti[i].rotMtx) );

			MTX_TransApply44( &(wk->confetti[i].rotMtx), &(wk->confetti[i].rotMtx),
				 wk->confetti[i].pos[0].x,  wk->confetti[i].pos[0].y,  wk->confetti[i].pos[0].z );


			G3B_LightColor( &(wk->cmdInfo), GX_LIGHTID_0, GX_RGB(11,11,11) );
			G3B_LightColor( &(wk->cmdInfo), GX_LIGHTID_1, wk->confetti[i].color );
//			G3B_LightColor( &(wk->cmdInfo), GX_LIGHTID_0, wk->confetti[i].color );
			{
				VecFx16 vec;

				VEC_Fx16Set( &vec, 0, FX16_ONE-1, -FX16_ONE+1 );
				VEC_Fx16Normalize( &vec, &vec );
				G3B_LightVector( &wk->cmdInfo, GX_LIGHTID_0, vec.x, vec.y, vec.z );

				VEC_Fx16Set( &vec, 0, -FX16_ONE+1, FX16_ONE-1 );
				VEC_Fx16Normalize( &vec, &vec );
				G3B_LightVector( &wk->cmdInfo, GX_LIGHTID_1, vec.x, vec.y, vec.z );
			}

		#if 1
			{
				MtxFx44  rotMtx;

				MTX_RotX44( &rotMtx, FX_SinIdx((u16)(wk->confetti[i].rot.x)), FX_CosIdx((u16)(wk->confetti[i].rot.x)) );
				MTX_Concat44( &rotMtx, &(wk->confetti[i].rotMtx), &(wk->confetti[i].rotMtx) );

				MTX_RotY44( &rotMtx, FX_SinIdx((u16)(wk->confetti[i].rot.y)), FX_CosIdx((u16)(wk->confetti[i].rot.y)) );
				MTX_Concat44( &rotMtx, &(wk->confetti[i].rotMtx), &(wk->confetti[i].rotMtx) );

				MTX_RotZ44( &rotMtx, FX_SinIdx((u16)(wk->confetti[i].rot.z)), FX_CosIdx((u16)(wk->confetti[i].rot.z)) );
				MTX_Concat44( &rotMtx, &(wk->confetti[i].rotMtx), &(wk->confetti[i].rotMtx) );

			}
		#endif


		#if 1
			G3B_MaterialColorSpecEmi(	&wk->cmdInfo,
										GX_RGB(31,31,31),		// speculer
										wk->confetti[i].color,			// emission
										FALSE					// use shininess table if TRUE
			);
		#endif



			G3B_PushMtx( &wk->cmdInfo );
			G3B_LoadMtx44( &wk->cmdInfo, &(wk->confetti[i].rotMtx) );

			G3B_Begin( &wk->cmdInfo, GX_BEGIN_QUADS );
			{
				G3B_Normal( &wk->cmdInfo, 0, 0, -FX16_ONE+1 );

				G3B_Vtx( &wk->cmdInfo, -CONFETTI_X_SIZE, -CONFETTI_Y_SIZE, 0 );
				G3B_Vtx( &wk->cmdInfo,  CONFETTI_X_SIZE, -CONFETTI_Y_SIZE, 0 );
				G3B_Vtx( &wk->cmdInfo,  CONFETTI_X_SIZE,  CONFETTI_Y_SIZE, 0 );
				G3B_Vtx( &wk->cmdInfo, -CONFETTI_X_SIZE,  CONFETTI_Y_SIZE, 0 );


			}
			G3B_End( &wk->cmdInfo );

			G3B_PopMtx( &wk->cmdInfo, 1 );
		}

		wk->cmdSize = G3_EndMakeDL( &wk->cmdInfo );
		DC_FlushRange( wk->cmdBuffer, wk->cmdSize );

		GF_ASSERT_MSG( wk->cmdSize < sizeof(wk->cmdBuffer), "cmdSize=%d, bufSize=%d", wk->cmdSize, sizeof(wk->cmdBuffer) );

		wk->transStartFlag = TRUE;

	}
}

static void DrawConfetti( TCB_PTR tcb )
{
	if( tcb )
	{
		CONFETTI_CONTROL_WORK* wk = TCB_GetWork( tcb );
		if( wk->transStartFlag )
		{
			G3_PushMtx();
			OS_TPrintf("[VINTR] Send Start\n");
			MI_SendGXCommand(3, wk->cmdBuffer, wk->cmdSize);
//			OS_TPrintf("[VINTR] Send End\n");
			G3_PopMtx(1);
 			wk->transStartFlag = FALSE;
		}
		else
		{
			OS_TPrintf("[VINTR] Send Threw\n");
		}
	}
}